Adding left button to UINavigationBar (iPhone)

前端 未结 3 1797
无人及你
无人及你 2021-02-02 09:23

I\'ve created a new navigation based iPhone app. I added this to the RootViewController.

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *add         


        
3条回答
  •  有刺的猬
    2021-02-02 09:47

    There is actually another answer, which is not listed here, but might be very useful in many cases. If you do not want to use UINavigationController, then self.navigationItem is not an option for you.

    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"imageName"] style:UIBarButtonItemStyleBordered target:self action:@selector(action:)];
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Bar Title"];
    navigationItem.leftBarButtonItem = barButton;
    [navigationBar pushNavigationItem:navigationItem animated:NO];
    

    You might want that when creating lightweight UIViewController with bar and buttons, but do not want navigation overhead.

提交回复
热议问题