我正在尝试将 UIViewController 推送到导航控制器上,然后将 UIBarButtonItem 添加到导航栏,以便我可以使用它来显示倒计时计时器。
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;