Question regarding Tab bar controller - objective-c

I am using [self.view addSubView:tabBarController.view];
But because of this viewDidAppear and viewWillAppear is not getting called so if I want to reset my view or update the contents of it, its not happening. Can u help me?

HI After some googling I have found the solution for the question. If you are using tabbar controller....then u can use :-
(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
method for invoking any function from other viewControllers.
Just you have to give
[viewController functionname];
that's it. Hope this post might help someone.

If you're linking against iOS 4.x SDK and lower, you should avoid using nested UIViewControllers.
But if it is really necessary, you should manually call viewWillAppear: (and all others) and make sure parentViewController property of your child view controller is referenced to UIViewController subclass that owns it.
P.S. If you'd like to add UITabBarController to fill all window contents, you can present it as modal view controller over another view controller or use rootViewController property of UIWindow class

Related

How to perform an action before a return from a destination view controller

I have the following issue: a source view controller A triggers a destination view controller B
A->B
that in turn turns on the camera and begins scanning barcodes.
Now, the segue used to push the destination view controller (B) is a push one, so, I have a tabbar navigation button allowing me to return to the source view controller (A). I need to make sure that before I return to the source view controller (A) I switch off the camera.
This doesn't happen right now (I can see in the console that the camera keeps refocusing despite the control being passed to the source view controller (A)).
How do I do that?
Thanks a lot in advance,
Peter
In view controller B, add the code to switch off the camera to the viewWillDisappear method.
Either way viewDidDisappar or viewWillDisappear will do it for you, make sure to release imagepickercontroller object in the dealloc as and when required.
viewWillDisappear is one option. Another option would be to use UITabBarController's delegate method
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

UINavigationController UIToolBar does not show up in my views

My UINavigationController contains a UIToolBar with 3 UIBarBottomItems - It has all been drag/drop designed in the storyboard. I want this UIToolbar to be shared on all my views. I have therefore set checked the "shows toolbar". But when I run it the UIToolBar is empty in all of my views. What could be the reason for this ?
I realize this is an old thread but I've just been struggling with this for a couple hours and finally figured out what was wrong. It was something simple so thought I would share. I was calling [self.navigationController setToolbarHidden:NO]; in viewDidLoad. The problem was that viewDidLoad is called before the view controller is pushed onto the navigationController so self.navigationController is nil. I moved the code to viewWillAppear: method and it worked.
UINavigationController have default toolbar. which you can use. you can use following code
[self.navigationController setToolbarHidden:NO];
in the topmost view controller and
[self setToolbarItems:items];
in all your view controllers, where items is an NSArray of that view controller's toolbar items.
select your initial view controller in the storyboard and embed it in navigation controller.
now all your pages should have the navigation bar.. if u manually dragged dropped the previous bars when u run the program it'll show both...
You'll have to remove the old ones and then modify the new one as required.

How do IOS know which viewController is being viewed and hence need viewWillAppear to be called

How does iOs know?
Does each view has a pointer to it's controller?
What happened?
When we pop a viewController from navigation, does the navigationController arrange which view should be called?
For example:
If I added:
[[BNUtilitiesQuick window] addSubview:[BNUtilitiesQuick searchController].view];
viewWillAppear will be called.
ios does know which viewControler viewwillappear should be called even under cases in the question. There is no way I can think of how they know that without a pointer from view to viewcontroller.
However, window doesn't know the viewController. I am passing the view outlet of the controller not the controller. How can iOs 5 knows that it has to call [[BNUtilitiesQuick searchController] viewWillAppear:YES]
Navigation Controller maintains a stack of view controllers.
Once a view controller is popped, it is removed from the stack, and now the view controller exactly below this is the first view controller.This is how it works.
You can check documentation for more details - http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html#//apple_ref/doc/uid/TP40011313-CH2

UIViewController within a UIViewController

So I have a viewControllerA, and I want to add another View managed by viewControllerB to it. There is only one UISlider activating a simple action in viewControllerB. It won't crash if I don't touch this UISlider, it will once I use UISlider. I am using ARC. I am using:
[self.view addSubView: viewControllerB.view];
to add viewControllerB to viewControllerA. Am I missing something? Thanks.
OK. It looks like a really simple situation. I just added one view controller and one action. Here is the demo project code on github: https://github.com/randomor/Demo
The reason why I want this to work is because I have another app that will create a view controller on the spot and add it to anther view. And I don't want to do it modally, because I don't want the new view controller to cover the whole screen. Thanks.
SOLUTION: So I'm now just using the latest ViewController containment API:
[self addChildViewController:viewControllerB];
It works! as long as I added this line, the event will be passed to its own controller and it stopped crashing.
i recommend you, to use the following code
in ViewControllerA.h
#import "ViewControllerB.h"
in ViewControllerA.m (where you want to push the new controller)
ViewControllerB *newController = [[ViewControllerB alloc]init];
[self presentModalViewController:newController animated:YES];
in ViewControllerB.m you will need
[self.presentingViewController dismissModalViewControllerAnimated:YES];
to make it vanish again.
concerning multiple controllers for one open screen (Apple ViewController Programming Guide):
Each custom view controller object you create is responsible for managing exactly
one screen’s worth of content. The one-to-one correspondence between a view controller
and a screen is a very important consideration in the design of your application.
You should not use multiple custom view controllers to manage different portions
of the same screen. Similarly, you should not use a single custom view controller
object to manage multiple screens worth of content.
You should try and avoid the practice of nesting UIViewControllers. While it is technically supported in iOS5, it is ill-advised, for many reasons, including the type of problem that you're having (you have a dangling pointer to a UIViewController, which is why you are crashing).
http://blog.carbonfive.com/2011/03/09/abusing-uiviewcontrollers/
Although this question is extremely vague, I imagine that you are not keeping a reference to View Controller B, and so when view B tries to interact with it, it causes EXC_BAD_ACCESS.
What's the object that is set as the target for the slider? If it's a EXC_BAD_ADDRESS, then you may not be retaining the target, most probably the view controller for the slider.

Cocoa Touch UITabBar action on tab switch

I have a UITabBar with a number of UITabBarItems. I've assigned a different view controller to each of these.
I want to load some data etc., when each button is clicked. Therefore I will like to know where to put that code? I tried implementing viewWillAppear and viewDidLoad in the view controller but those didn't get called.
I know that when you assign a delegate to a UINavigationController, the component UIViewController delegate methods are not called. It seems likely that the same is true of UITabBarController.
I would try implementing the UITabBarControllerDelegate protocol and implementing the tabBar:didSelectViewController: method.
Are you sure your custom controllers inherit from UIViewController?
Don't forget the signature for the viewWillAppear is viewWillAppear:animated:
I'm working off the beta 5 right now, and it works just fine (I'm also using a TabBar).
Write your code in viewdidappear function.but i didn't try