Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当我的应用程序返回前台时在我的视图中调用方法_Ios_Uiviewcontroller - Fatal编程技术网

Ios 当我的应用程序返回前台时在我的视图中调用方法

Ios 当我的应用程序返回前台时在我的视图中调用方法,ios,uiviewcontroller,Ios,Uiviewcontroller,当应用程序从后台返回时,如何调用方法 我知道有一些方法可以在app委托中调用,但我想在我的视图中调用一个方法 这样做的最佳方式是什么 提前谢谢 您应该为UIApplicationWillEnterForegroundNotification通知注册所需的视图控制器,例如在initWithNibName:nibBundleOrNil: - (id)initWithNibName(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {

当应用程序从后台返回时,如何调用方法

我知道有一些方法可以在app委托中调用,但我想在我的视图中调用一个方法

这样做的最佳方式是什么


提前谢谢

您应该为
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
方法,我需要回忆一下吗?我知道这是一个新问题,但当我第一次问这个问题时,我还没有意识到这是我的问题。