开发者

BarButtonItem does not show up

I created a new window based application, and a RootViewController that sublcasses UIViewController. I created a UINavigationController in the AppDelegate and when I add the UINavigationController's view to the window, I do see the n开发者_如何学Goavigation bar on top. However, I cannot seem to add a button to the navigation bar - there are no compile errors, but the button (and the title) does not show up. The code is below:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    RootViewController * rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

    UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleDone target:nil action:nil];
    navigationController.title = @"Foo";

    navigationController.navigationItem.rightBarButtonItem = next;

    [self.window addSubview:navigationController.view];

    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];
    return YES;


}

What am I doing wrong?


Change this:

navigationController.navigationItem.rightBarButtonItem = next;

to this:

rootViewController.navigationItem.rightBarButtonItem = next;


May be style:UIBarButtonItemStyleDone only used in editing mode is YES. If in Root controller or sub view controller, you may try call self.editing = YES, but in AppDelegate you can't.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜