简体   繁体   中英

Switching UINavigationViewController to UITabBarController with Segues

I am changing my app to use UITabBarController instead of UINavigationViewController . I replaced controllers accordingly and app launches with tabs successfully. Later in the code I came across some difficulties using segues where lines like

[self performSegueWithIdentifier:@"ImageViewController" sender:self];

won't work producing error

" Push segues can only be used when the source controller is managed by an instance of UINavigationController "

When I embedded UINavigationController into the initial FirstViewController , line above worked fine. I need that line to switch between views and pass some data to another view controller.

The problem is that using segue identifier to go to SecondViewController hides TabBar navigation (unless I wrap SecondViewController in UINavigationController again and so on). That is not the solution.

Question : How to use UITabBarController and still take advantage of segues while keeping tab navigation visible?

在此处输入图片说明

"Push segues can only be used when the source controller is managed by an instance of UINavigationController"

Sounds to me like you are using a push segue somewhere outside a navigation controller. Try to select all "segue bubbles" in interface builder that are not inside a navigation controller:

塞格泡泡

and check the segue's style in the right pane:

Segue设置

If the style is set to the value push as shown above change it to modal or custom :

将样式更改为模式

There is something wrong with your connections. If you are using interface builder (storyboard) then your connections should look like this. See pic

Notice you are missing UINavigation Title headers. Also the gray area below on each view controller means that space is reserved for images for UITabBarController

Another problem is your UIToolBar. Looks like its sitting on top of where UITabBar will be displayed. That may/may not get your app rejected by apple since you already have a UINavigationController and UITabBarController. If you need more buttons/options on that page make them UIButtons instead.

在此处输入图片说明

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