我有一个基于NavigationController的iPhone应用程序,有一个navigationBar和一个工具栏。下面是它的基本工作原理:
applicationDelegate将"SplashScreen“作为模式视图推送到RootViewController上。当启动画面出现时,应用程序会做一些工作,并且基于用户的位置,要么直接取消模式视图,要么取消模式视图并将另一个视图推到导航堆栈上。
RootViewController和子视图都有带Add按钮的工具栏。我的问题是:当第二个视图被自动按下时,Add按钮调用它的父控制器的代码。如果您忽略此操作,然后再次按下add按钮,它将调用正确的代码。
下面是我的一些代码。
在RootViewController的viewDidLoad中,我有:
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
[self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];在子控制器(LocationListsController)的viewDidLoad中,我有:
addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
[self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];(是的相同的代码,它们都有addClicked事件)
在RootViewController中,viewWillAppear是我实际推送子视图的地方:
if (((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex != -1)
{
GeoLocation *location = [((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).locations objectAtIndex:((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex];
((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex = -1;
if (lController == nil)
{
LocationListsController *aController = [[LocationListsController alloc] initWithLocation:location];
self.lController = aController;
[aController release];
}
[[self navigationController] pushViewController:lController animated:YES];
}视图的推送工作正常。我唯一的问题是工具栏上的addButton。有谁有什么想法吗?
发布于 2010-01-22 19:38:31
尝试从viewDidAppear而不是viewWillAppear推送“子”视图控制器。
https://stackoverflow.com/questions/2113841
复制相似问题