简体   繁体   中英

Cancel button instead of a back button in Navigation Controller

I have a general question concerning the navigation between views.

I have a view controller 1 embeded in a navigation controller. In the nav bar, I have a button to do add data, when pushed, it goes to view controller 2 through segue Show (in Storyboard). In view controller 2, I return to view controller 1 after collecting data when I click the button save in nav bar on the right. I collect data with:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {...}

I would prefer instead of a back button to have a cancel button in the view controller 2 to return to view controller 1.

I feel something is wrong in my design but I dont know what.

In fact I am looking for something very similar to app clock.

Do you have any idea?

Edit: Here is the story board. you will notice the loop beween the two controller. how to do when I click save to not have a back button automatically on the first controller?

故事板

You just have to select your UIBarButtonItem, click at show Attributes Inspector, click at Identifier and select "Cancel" from the drop-down menu.

在此输入图像描述

在此输入图像描述

@IBAction func cancelDownload(sender: AnyObject) {
    dismissViewControllerAnimated(true, completion: nil)

}

You can customize the text of the back button by adding this code to the view controller that contains it (in viewDidLoad ):

let backItem = UIBarButtonItem(title: "Cancel", style: .Bordered, target: nil, action: nil)
navigationItem.backBarButtonItem = backItem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM