I am converting my single view application into one that is based on tabs. I have most of the layout done so I'm trying to wire up all the components now and I'm stuck trying to figure out how to do two things:
When I pick a bonus from my UITableView, I want it to open my 2nd tab with the info for the selected row. I'm not sure how to do that.
If I go straight to one of the other tabs, I want to have it just display the details for the first visible row of the UITableView. I'm not sure how to set such a default value.
I'm not exactly sure what code you would need to see for the above, but I am using Xcode 9 and Swift 4. I've googled and searched YouTube and Stack Overflow, and the answers are either all for Objective-C or are about the UITabBar obscuring the last row of UITableView data (which is not an issue I'm having).
EDIT: I seem to have semi-gotten it to work by changing my prepare (for segue) and then via Interface Builder, deleting the segue from the UITableView to the tab's viewController. However, this still doesn't light up the proper tab in the UITabBar. Also, this is still wrapped in the original Navigation Controller. Which allows me to move back and forth, but isn't the intent. When I tried removing the Navigation Controller, I had to use a "Show" or "Modal" type segue, which covers up the UITabBar, and offers no way to get back out of the detail view. I want to use the UITabBar to provide the back and forth that the Navigation Controller used to handle so I can gain the space at the top of the screen back.
The simplest is probably to register a Notification Center observer in your second tab's view controller. Whenever you have an item to show, simply trigger the notification from your first tab's view controller attaching the object you need to show to the notification.
Related
I have an application with a drop down menu as the titleView of my NavigationController. When a user selects an item of the drop down menu, the entire view should switch contents, however, the NavigationBar should remain the same. The NavigationBar should not have to reload any data and the titleView should remain a drop down menu.
The original view upon opening the app:
The view upon touching the dropdown menu:
I currently see a few ways of going about this:
Set up a UIViewController for each option, perform the segue, and reload the data.
Why this is bad: I will have to set up a segue identifier for each ViewController, meaning if I have 15 options in my drop down menu, I will have 210 segue identifiers laying around. I will also have to reload all of my NavigationBar data.
Why this is good: I will have a clear area to set up each individual view.
Programmatically add and remove UIButtons, UILabels, and UIWhatevers as I need them.
Why this is bad: This will create a lot of code inside just one ViewController and things could get difficult to debug.
Why this is good: The NavigationBar never gets reloaded.
Add a container and embed a unique ViewController for each item as I need it.
Why this is bad: All of my work would still be in the main ViewController and I'd have to manage the logic of the embedded ViewController inside one Controller.
Why this is good: The NavigationBar never gets reloaded.
A completely different method suggested by someone else because I don't know the most efficient way of doing this.
So, in conclusion, what is the most efficient way to maintain state of my NavigationBar when switching my main content in my View?
Option 3 is the best out of the three you listed. Options 1 and 2 will get more and more complicated the more view controllers you want to add. Compare that to UINavigationController, UITabBarController, or UIPageViewController which do not need to be more complicated in order to handle 10 screens vs. 100 screens.
I would suggest creating a custom container view controller (Apple's Reference)
I see 2 immediate approaches to implementing this:
Subclassing UIViewController - this is how Apple's container view controllers are implemented
Subclass UITabBarController - I have done this successfully, subclassing UITabBarController to show a custom tab bar at the top instead of along the bottom.
I am new to xcode and IOS (and this board. First post).
I am completely flummoxed by a design problem and unsure how to approach.
I have three buttons, each of which calls a new array of pages that need to navigate horizontally with swipe gestures and have their own buttons.
The three buttons in the parent work exactly like a tab bar except they have to be bigger and higher than a tab bar would be. The called page arrays mostly work like a pageviewcontroller except that the pages need to have a button/indicator below to allow non sequential navigation. The target HAS TO LOAD WITH A SEGUE.
The problem I'm encountering is that using a modal segue to load a pageviewcontroller and prepareForSegue to keep the master/parent view controller visible results in my buttons being inaccessible. I assume its because I cant click thought the child view controller.
Secondly, I don't know if its possible to customize the page indicator dots of a pageviewcontroller so they can look like a bar with graphics.
Here are my specific questions:
Is it possible to load a view controller with a modal segue and still access my buttons? Can the child be resized?
can i customize the buttons/indicators in a pageviewcontroller. Can you point me to some code?
should navigation like this be done with some completely different approach? What about a view controller container?
Here's a diagram (cant post images directly yet)
I've found the answer to my second question: It seems that pageViewController's indicators are not customizable in any way. This rules out pageViewController for what I need.
9 Views in 10 hours. Is this not the best forum for questions like this or is there something wrong with my post?
i have implemented a tabbarcontroller with 5 tabs each connected to a view.
the tabBarcontroller is created and default view allocation happens in another view.
everythine looks fine but i have a bug.
each view in the tab have buttons that trigger other views. these views don't have tabs so to get back to a tab view i use a back button.
when i press the back button i don't want the view ( with the tab ) to be created from scratch. so i have put the relevant code in viewdidload rather than viewwillappear.
( this choice is because this view downloads data from server and it becomes time consuming to put the code at this point in viewwillappear )
However if i am returning from current tab to a tab that i had previously touched and viewed. I want view to be loaded from scratch because data should be downloaded again at this point. but since i am using viewdidload rather than viewwillappear the old view is not refreshed.
how can i achieve this conditional refreshing of view depending upon whether i am coming from another tab or a from a view with back button
One way to do this is the isMovingToParentViewController method in your view controller. This will enable you to detect if your current stack has been popped from navigation controller.
There's an answer here that explains how to use it, and links to Apple's documentation.
As you can see from that thread, you can also use NSNotificationCenter to do this.
i want to use a tab bar on top of the view controller not in the bottom. after searching, i found out it's against Apple's UI Interface Guidelines and it should always be at the bottom. However, my app has to have also one at the top. Anyway, i was thinking of using nested segues. For example, if we have three view controllers that each has 3 buttons on top that resemble the tab bar items, and i'm positioned on the first VC (hence, the first button is highlighted). When i press on the second button it gets highlighted and segues to the second VC. Then if i press of the first button, i'll be taken back to the first VC. My question here is if i worked using this paradigm, will the VC's be stacked? will the performance of the app decrease? can i achieve this in a better way in case the answer of the previous questions were negative?
try these projects
MHCustomTabBarController
ICViewPager
JCMSegmentPageController
QMBTabs
I've set up a storyboard with a UITabBarController object and I'd like to add two tabs to that, but both tabs are going to be exactly the same except for the data they will display. Obviously, I could drag in two new view controllers and connect them up and just maintain the views separately, but I don't want to do this at all.
Does anyone know the most efficient way of doing this?
I've done this by using a regular UIViewController with a tab bar at the bottom, rather than using a UITabBarController. You just have to use the UITabBar delegate method, tabBar:didSelectItem:, to detect the tab clicks, and then do whatever you need to do to switch what data is displayed in the single view.