UINavigationController and back button action

后端 未结 7 2075
-上瘾入骨i
-上瘾入骨i 2021-01-04 09:09

I have an two controllers 1st is self and 2nd is maincontroller, where I\'m pushing maincontroller in stack

7条回答
  •  萌比男神i
    2021-01-04 09:16

    Create your own UIBarButtonItem and set it as the leftBarButtonItem in viewDidLoad method of mainController.

    For example (here I used a system item but you can also create a different one, see class reference for details).

    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showAlertView:)];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    // only if you don't use ARC
    // [leftBarButtonItem release];
    

    where

    - (void)showAlertView:(id)sender
    {
        // alert view here...
    }
    

提交回复
热议问题