2
我试图将UIViewController推送到导航控制器上,然后将UIBarButtonItem添加到导航栏中,以便我可以使用它来显示倒数计时器。将UIBarButtonItem添加到推送到UINavigation控制器上的UIViewController
UINavigationController *navController = [[Session sharedInstance] getNavigationController];
GamePlayViewController *gameController = [[GamePlayViewController alloc] initWithNibName:@"GamePlayViewController" bundle:nil ];
UIBarButtonItem *timerBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
gameController.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:timerBtn, nil];
[navController pushViewController:gameController animated:YES];
当我使用上面的代码不起作用。我也尝试从控制器本身的ViewDidload方法做到这一点,但没有骰子。我甚至尝试使用rightBarButtonItem却得到一个错误,说明
"to uncaught exception 'NSInvalidArgumentException', reason: 'Fixed and flexible space items not allowed as individual navigation bar button item. Please use the leftBarButtonItems (that's plural) property.'
*** First throw call stack:"
UIBarButtonItem *timerBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
self.navigationItem.rightBarButtonItem = timerBtn;
曾任职谢谢! – 2013-03-10 20:27:19