TabBarController - reload SecondViewController - ios

I am making a TabBarController application using the template provided by Xcode and I need to reload the second view controller everytime it is clicked. How do I do this ?
Thanks

Whenever the tab bar switches the view controllers, the viewcontroller viewWillAppear function will be called
So add the code in the viewWillAppear function of the UIViewController

Related

Dismiss Modally presented view makes tab bar controller (kind of) reset

I have an app which has tab bar controller as main controller. Each tab has a series of views with navigation controller and I normal push and pop those view in stack.
Weird problem is
Case 1 : If I create a UINavigationController and make a new viewController as its root, and present this NavigationController. Within this new navigation stack, I can easily present a view modally and dismiss it without a problem.
Case 2: Now without make a new UINavigationController, I present a view, and when I dismiss a view, the view beneath is behave weirdly. For example, it's the presenting view was UICollectionView, it just scroll back to 1st cell, like it's doing "reload" action and "scrollTo" the first cell. If the presentingView is a pushed view from rootView, it will just popToRoot view, which is definitely not intended.
I didn't have this problem until I implement UITabbarController, so I guess, I should know more that's going on under the hood when presenting a view and dismiss a view in UITabbarController.
I GUESS, when dismiss a view in UITabbarController view, it sort of "RESET" everything to the very first view of it's current tab. I really am not sure it's trure though.
I know it's kind of conceptual, but I can't help to think there must be something critical I am missing here.
I made silly mistake that I sublclass UITabbarController and define navigation controlllers in viewDidAppear instead viewdidLoad, so when I make the window's rootview to tabbar controller, the navigation controllers are not set properly. That's why all punky things happened. It would be nicer if just crash instead of this weird behaviors.
You can try this to go back to your first viewcontroller.
- (IBAction)buttonPressedFromVC2:(UIButton *)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
} // This is going back to VC1.
This method is will be in second viewcontroller.m file. It is button click method.

Navigation bar disappears when show segue is executed from one ViewController to another?

I have a ViewController with a tableView in it and when I tap on a cell it performs a segue(show) from that view controller to another viewController with a navigationController embed in it. I have the segue going directly to the ViewController not the navigationController. But when the segue executes, it brings me to the second viewController but the navigation bar that used to be there is gone. How do I fix this?
Your segue must be connected to the SecondViewController's NavigationController. Remake your segue connection from your FirstViewController to SecondViewController's NavigationContoller.

Retain UIViewController in TabBarController

I have created my own custom TabBarController which is subclass of UITabBarController and i override this function :
- (void)setSelectedViewController:(UIViewController *)selectedViewController {
[super setSelectedViewController:selectedViewController];
}
Inside the Tab in TabBarController, let say Tab NO.4, i can push another ViewController. So now in Tab NO.4 have a new ViewController up on it. And now, i can tab on another Tab, let say Tab NO.3. So the problem appear here, when i tab again Tab NO.4, the new ViewController is disappeared, it doesn't retain.
How can i make it retain? Facebook app is one of the example.
For that you have to take saperate navigation controller for each tab.
Suppose you have three tabs you nee to take three navigation controllers.
http://www.appcoda.com/storyboard-tutorial-create-tab-bar-controller-and-web-view/
You can take UINavigationController as a view controller instead of UIViewController in which tab you want to push a new view controller. It will automatically retain that controller after the selection changed. You also can hide navigation bar if not required.
Here is an example:
http://www.raywenderlich.com/50308/storyboards-tutorial-in-ios-7-part-1

ios development: awakefromnib called every time viewcontroller appears

Some background at first: I'm developing storyboard based application (ios7) where UITabbarController is the root controller. One of the tabs contain navigation controller. Viewcontroller embedded to that navigationcontroller has button, which opens new viewcontroller when pressed. I'm using push segue to do that.
My issue is following: Every time I press the button and new viewcontroller opens, awakefromnib is always called. I'm trying to do some initializing in the awakefromnib function, but now it is not possible because the function is called always when the viewcontroller appears.
Any help with this?

How to dismiss a view that is presented with pushViewController method?

my situation is as follow:
1) i have rootViewController with navigationController and add button in the toolbar. When i press i push another view using pushViewController method. This view called chooseTypeView which has only tableview with two cells.
2) when any cell is clicked third view will be pushed using the same method to enter some data.
3) now i want when i press the "Done" button in the keyboard to navigate back to rootView controller and dismiss all views in between the current steps and the root view.
i'm using #Protocol to connect views and i could pass information from the last view to the root view but i couldn't dismiss it.
Thanks for all and i hope that i make myself clear.
I could answer this question my self.
In the delegate method i can call [self.navigationController popViewControllerAnimated:YES] which will remove the current view from navigationController views stack.
For SWIFT use the below code:
self.navigationController.popViewControllerAnimated(true)

Resources