Ios 当我的应用程序返回前台时在我的视图中调用方法
当应用程序从后台返回时,如何调用方法 我知道有一些方法可以在app委托中调用,但我想在我的视图中调用一个方法 这样做的最佳方式是什么Ios 当我的应用程序返回前台时在我的视图中调用方法,ios,uiviewcontroller,Ios,Uiviewcontroller,当应用程序从后台返回时,如何调用方法 我知道有一些方法可以在app委托中调用,但我想在我的视图中调用一个方法 这样做的最佳方式是什么 提前谢谢 您应该为UIApplicationWillEnterForegroundNotification通知注册所需的视图控制器,例如在initWithNibName:nibBundleOrNil: - (id)initWithNibName(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {
提前谢谢 您应该为
UIApplicationWillEnterForegroundNotification
通知注册所需的视图控制器,例如在initWithNibName:nibBundleOrNil:
- (id)initWithNibName(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(yourMethod:) name:UIApplicationWillEnterForegroundNotification object:nil];
// Whatever else your init method should do here...
}
return self;
}
- (void)yourMethod:(NSNotification *)notification
{
// whatever you want to do here...
}
确保您也在dealloc
中注销:
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
感谢@JRG Developer和@JustSid的回答,但我仍然没有任何运气。我的问题是,在我的应用程序重新进入前台后,UIImageView对触摸没有响应。我最初使用的是
touchesbreated
方法,我需要回忆一下吗?我知道这是一个新问题,但当我第一次问这个问题时,我还没有意识到这是我的问题。