我想知道我是否以正确的方式做到了。我有我的类UIMyView,我添加到我的主UIView。在那个UIMyView我使用NSTimer做一些事情,毕竟我调用removeFromSuperView方法返回主UIView。我想注意我的UIMyView何时关闭。我使用NSNotificationCenter来做这件事,但也许还有其他更好的方法吗?
编辑: 好的,但我想你,你不理解我。使用setHidden或containsObject我们需要执行此操作,例如puttin it click Button或类似的东西。我想做的是检查何时关闭UIMyView而没有任何用户交互。
答案 0 :(得分:1)
尝试这个。可能这对你有帮助
BOOL hasMapView = [self.contentView.subviews containsObject:self.mapView];
UIView *fromView, *toView;
if (hasMapView)
{
[btnMode setImage:[UIImage imageNamed:@"map-mode.png"] forState:UIControlStateNormal];
fromView = self.mapView;
toView = self.tblVideo;
[self.tblVideo reloadData];
}
else
{
fromView = self.tblVideo;
toView = self.mapView;
[btnMode setImage:[UIImage imageNamed:@"list-mode.png"] forState:UIControlStateNormal];
[self reloadPins];
}
答案 1 :(得分:0)
使用它而不是使用removeFromSuperView
[urViewnm setHidden:YES];
答案 2 :(得分:0)
检测视图是否已关闭
BOOL isViewActive = [self.view.subviews containsObject:UIMyView];
答案 3 :(得分:0)
使用协议可以实现:
1.在CustomViewController.h中创建协议
@protocol CustomViewControllerDelegate <NSObject>
- (void) didCustomViewControllerRemove:(id)sender;
@end
@interface CustomViewController : UIViewController
@property (retain) id <NSObject, CustomViewControllerDelegate> delegate;
@end
#import "CustomViewController.h" @implementation CustomViewController - (IBAction)cancelBtnPressed:(id)sender { [_delegate didCustomViewControllerRemove:self]; }
#import“CustomViewController.h”
@interface UIMyView:UIViewController'&lt;'CustomViewControllerDelegate'&gt;'
{}
- (void) addCustomViewControllerMethod { CustomViewController *obj = [CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil]; [self.view addSubView: obj]; obj.delegate =self; } - (void)didCustomViewControllerRemove:(id)sender { [self dismissViewControllerAnimated:YES completion:nil]; }