从pushViewController视图设置后退按钮

时间:2016-08-11 21:38:06

标签: ios viewcontroller back-button

我有一个viewController A,是否有可能在推送到viewController B时预先设置后退按钮。

Controller *B = [Controller viewControllerFromStoryboardWithProfile: profile editMode: NO];

    UIBarButtonItem *newBackButton =
    [[UIBarButtonItem alloc] initWithTitle:@"Home"
                                     style:UIBarButtonItemStyleBordered
                                    target:nil
                                    action:nil];

    [B.navigationItem setBackBarButtonItem:newBackButton];

    [self.navigationController pushViewController:B animated:YES];

这样的东西?

1 个答案:

答案 0 :(得分:2)

试试这段代码:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Home"
                                 style:UIBarButtonItemStyleBordered
                                target:nil
                                action:nil];

self.navigationItem.backBarButtonItem = backButton;
[backButton release];

[self.navigationController pushViewController:anotherViewController];

来源:How to create backBarButtomItem with custom view for a UINavigationController