Create a custom left back button on UINavigationBar WITH the standard arrow on the left

后端 未结 6 1606
情书的邮戳
情书的邮戳 2021-02-05 03:27

When I create a custom back button, I use the following code:

    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithTitle:@\"Yeah\" style:UIBarButton         


        
6条回答
  •  梦谈多话
    2021-02-05 04:06

    The easiest thing to do would be to set the title, in the parent controller (i.e. the one you want to nav back to). If you don't want this to be the same as the actual title displayed in that VC's view, you can change the title in viewWillDisappear to what you want on the next VC's back button, and then change it back to what you want in the parent in viewWillAppear.

    If you are using storyboards, you can also set the back title directly in IB.

    Finally, in order to create a custom back button, you can do something like:

    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Details" style:UIBarButtonItemStyleBordered target:nil action:nil];
    

    ...just be sure to do this in the presenting (or parent) view controller, not the view controller being loaded (the presented controller).

提交回复
热议问题