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