2012-01-10 121 views
0

我需要在我的应用程序中按住主页按钮。 当用户按下我的DetailedViewController中的home按钮时,我需要触发方法[self.navigationController popViewControllerAnimated:YES]。 请帮助我。 怎么办?在iphone上按住主页按钮

回答

2

退房- (void)applicationWillResignActive:(UIApplication *)application方法在你的应用程序委托。它会赶上事件。然后你可以根据需要处理它。例如,使用默认通知中心发布通知,并在需要做某些事情的课程中获得该通知。

+0

一切都很清楚。我使用'self.navigationController.visibleViewController.nibName'的方法我知道什么视图控制器是可见的,当用户按Home按钮。但是,如果我的可见视图控制器的笔尖名称是'DetailedViewController',我需要弹出它(这很简单),但我也需要**取消应用程序尝试关闭我的应用程序** – Oleg 2012-01-10 13:55:15

+0

您无法关闭应用程序后关闭应用程序按钮被按下。 – 2012-01-10 14:21:44

1

你想要什么?你想回到主页(根)还是想回到前一页?

只是尝试了这种代码在你回到你的出发或家庭控制器

[self.navigationControler popToRootViewControllerAnimated:YES]; 
1

由于ПавелОганесян形容:

// post notification 
- (void)applicationWillResignActive:(UIApplication *)application 
{ 
    [[NSNotificationCenter defaultCenter] postNotificationName:@"TestNotification" object:self]; 
} 

现在DetailedViewController .m文件

// add observer 
- (void)viewDidLoad 
{ 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveTestNotification:) name:@"TestNotification" 
               object:nil]; 
} 

- (void) receiveTestNotification:(NSNotification *) notification 
{ 
    // do the needful 
} 

希望它可以帮助你...