我在显示导航栏的rightBarButtonItem时遇到问题-我正尝试在设置我的UINavigationController的应用程序代理中以编程方式创建它。
代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
RSCListViewController *list = [[RSCListViewController alloc] initWithStyle:UITableViewStylePlain];
self.navController = [[UINavigationController alloc] initWithRootViewController:list];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"+"
style:UIBarButtonItemStylePlain
target:list
action:@selector(addPressed:)];
self.navController.navigationItem.rightBarButtonItem = barButton;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[DatabaseManager openDatabase];
return YES;
}运行应用程序时,导航栏上未显示按钮项。
我不确定我是否遗漏了什么明显的东西-我尝试使用相关的堆栈溢出线程来纠正这个问题,但没有取得任何成功。
感谢您的帮助。
发布于 2012-09-13 04:42:40
您需要将栏按钮项附加到自定义视图控制器,而不是导航控制器。来自Updating the Navigation Bar
此外,导航控制器对象使用与导航堆栈上的视图控制器关联的导航项( UINavigationItem类的实例)动态构建导航栏的内容。因此,要更改导航栏的内容,必须为自定义视图控制器配置导航项。
(...)
导航控制器按如下方式更新导航栏的右侧:
因此,请替换:
self.navController.navigationItem.rightBarButtonItem = barButton;通过以下方式:
list.navigationItem.rightBarButtonItem = barButton;https://stackoverflow.com/questions/12395687
复制相似问题