how to create back button in navigation bar

后端 未结 3 1668
北恋
北恋 2020-12-06 09:44

I have 2 page. first is tableView and second is view when I to click on any cell go on to next page (view) in way modal segue. I want add back button in next page of navigat

相关标签:
3条回答
  • 2020-12-06 09:51

    As you said in your comment you use a modal controller

    Add the following in viewWillappear

         UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:self action:@selector(Back)];
         self.navigationItem.leftBarButtonItem = backButton;
    

    And in

    - (IBAction)Back
      {
        [self dismissViewControllerAnimated:YES completion:nil]; // ios 6
      }
    
    0 讨论(0)
  • 2020-12-06 10:03

    Swift 3

    let backButton: UIBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(back))
        self.navigationItem.leftBarButtonItem = backButton
    
    func back() {
        self.dismiss(animated: true, completion: nil) }
    
    0 讨论(0)
  • 2020-12-06 10:04

    I had similar issue, but I am using Swift. Here is the answer in Swift 2.2.

            override func viewWillAppear(animated: Bool) {
                let backButton: UIBarButtonItem = UIBarButtonItem(title: "Back", style: .Plain, target: self, action: #selector(back))
                self.navigationItem.leftBarButtonItem = backButton;
                super.viewWillAppear(animated);
            }
    
            func back() {
                self.dismissViewControllerAnimated(true, completion: nil)
            }
    
    0 讨论(0)
提交回复
热议问题