我有一个UISplitViewController(完美工作),我想在顶部显示按钮,以纵向模式显示弹出菜单。
AppDelegate代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
splitViewController = [[MySplitViewController alloc] init];
MasterViewController *master = [[MasterViewController alloc] init];
PicsTableViewController *detail = [[PicsTableViewController alloc] init];
//create NavigationControllers
UINavigationController *masterNav = [[UINavigationController alloc] initWithRootViewController:master];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detail];
[master release];
splitViewController.viewControllers = [NSArray arrayWithObjects:masterNav, detailNav, nil];
[masterNav release]; [detailNav release];
splitViewController.delegate = detail;
[detail release];
[self.window addSubview:splitViewController.view];
[self.window makeKeyAndVisible];
return YES;
}
PicsTableViewController(委托)代码:
//add button on top
- (void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem*)barButtonItem
forPopoverController:(UIPopoverController*)pc
{
barButtonItem.title = aViewController.title;
self.navigationItem.rightBarButtonItem = barButtonItem;
}
- (void)splitViewController:(UISplitViewController *)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)button
{
self.navigationItem.rightBarButtonItem = nil;
}
按钮从不显示,我的代码出了什么问题? 感谢
答案 0 :(得分:3)
检查aViewController
实际上是否有title
属性,如果没有任何字母,则按钮不会出现。
我遇到了同样的问题,当我硬编码时:
barButtonItem.title = [NSString stringWithFormat:@"hello"];
按钮出现并正常工作。
我认为引用导航没有标题,这就是为什么它不起作用。