ViewDidLoad Not Called in UITabBar application - uitabbarcontroller

I am using Tabbar view controller as parent view controller. I am adding it from interface builder as shown in the below screen shot. Everything is working fine but the viewdidload,viewwillappear and viewdidappear methods are not calling from the begining. even if the viewcontroller is loading for the first time also. can any one please help me out code in my app delegate is
ScreenShot of IB: http://i58.tinypic.com/u4o6w.png
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.backgroundColor = [UIColor whiteColor];
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
self.window.rootViewController = self.tabBarController;
//[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
I am able to see the loaded views but the methods are not calling.
Can any one please help me out

Related

How can I trigger one UIViewController of the UITabBarController from another UIViewController?

I have a project that is a "tab-bar controller" app. The first button is essentially a Home screen. The second one displays a UITableView of content. The third button displays a different UITableView, etc.
From the first view (Home), I have a button on the page that is functionally equivalent to the second-button of the tab controller. It is an alternative path to get to that UITableView. I do not want to send a button press to the AppDelegate's UITabBarController.
The code in HomeViewController that I want is essentially this:
-(IBAction) touchInsideButton:(id)sender {
[self presentModalViewController: [appDelegate secondViewController] animated:YES];
}
or
-(IBAction) touchInsideButton:(id)sender {
AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];
[appDelegate launchSecondViewController: self];
}
where, "launchSecondViewController" is (uncomment-out one of the two lines)
-(void) launchSecondViewController: (id) sender {
// [self.tabBarController presentModalViewController: secondViewController animated:YES];
// [self.tabBarController.navigationController pushViewController: secondViewController animated:YES];
}
Regardless, all three approaches give the same error:
2013-05-16 12:04:26.977 MyApp[55273:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .'
* First throw call stack:
The problem is that this instance of the second view controller, which you refer to as secondViewController, is already in the interface, as a child of the tab view controller. You cannot have it be there and also present or push it.
The way to manipulate a tab bar controller in code is to set is selectedViewController (or selected index). Try doing that instead.

iPhone ModalViewController from First Tab Bar View

I am trying to launch an initial login/registration screen before my TabBarController View loads. I have read that putting a ModalViewController in the First View is a good way to go. This works, but I am trying to add navigation controls to the ModalViewController. I am getting the following issues:
1 - ERROR: Property 'navigationController' not found on object of type 'AppDelegate'
2 - WARNING: Initializing 'AppDelegate *'with an expression of incompatible type 'id'
here is the code on my ModalViewController:
-(IBAction)signUpButtonTapped {
// i need to get the control for main navigation controller
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
[appDelegate.navigationController popToRootViewControllerAnimated:NO];
// create object from app main view to push it
SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:#"SignUpViewController" bundle:nil];
[AppDelegate.navigationController pushViewController:signUpViewController animated:YES]; }
Anyone have any ideas? Thanks so much!
There are Two Problems in your code
1) Accessing the OBJECT with class name. It must be appDelegate.nav... (small a for Solving 1 ERROR)
[appDelegate.navigationController pushViewController:signUpViewController animated:YES];
2) Type Casting the assignment (for Solving 2 Warning)
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
So your Complete working Code must go as
-(IBAction)signUpButtonTapped {
// i need to get the control for main navigation controller
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[appDelegate.navigationController popToRootViewControllerAnimated:NO];
// create object from app main view to push it
SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:#"SignUpViewController" bundle:nil];
[appDelegate.navigationController pushViewController:signUpViewController animated:YES];
}
AppDelegate instance declaration is like this:
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
Change this and u r good to go.
In your Code Modify this Line
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
as
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
and try now
1.make sure your appDelegate have a UINavigationController property called navigationController.
2.Line 2 of your code:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
3.last line of your code:
[appDelegate.navigat.... NOT:[AppDelegate.navigatio....

Pass UIEvent from UIView in CCUIViewWrapper to CCLayer

I have a CCLayer with a UIViewController.view added to the layer via CCUIViewWrapper.
UIViewController *vc = [[UIViewController alloc] initWithNibName:#"Book" bundle:nil];
vc.view.backgroundColor = [UIColor whiteColor];
wrapper = [CCUIViewWrapper wrapperForUIView:vc.view];
wrapper.contentSize = CGSizeMake(320, 480);
[self addChild:wrapper];
The view has a UIButton, which ideally responds to Touch event, and call an IBAction.
But I can't figure out how to make the UIButton call the IBAction in CCLayer. The reason that the button calls an IBAction in CCLayer is that the action planned to do is to interact with the elements of CCLayer.
Can anyone give me some lights?

how to create menu on any other View in cocos2D

how to create menu on any other View it mean's i m created a UIView and i want to add MenuButton on it. This is my code but it is not working properly.. The UIView is hides the MuneButton..
UIView *aview;
aview = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 300,250)];
aview.backgroundColor= [UIColor redColor];
[[[CCDirector sharedDirector] openGLView] addSubview:aview];
// Standard method to create a button
CCMenuItem *menuItem1 = [CCMenuItemImage
itemFromNormalImage:#"Icon.png" selectedImage:#"Icon.png"
target:self selector:#selector(NextButton:)];
menuItem1.position = ccp(100, 60);
CCMenu *starMenu = [CCMenu menuWithItems:menuItem1, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];
and
(void) NextButton: (CCMenuItem *) menuItem
{
NSLog(#"Button1");
}
how to add Menu on UIView. I Try with AddSubview removing addChild. And i try aview removing self..
Hope it help to you..
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index
When you add a subview to a UIView, you are essentially adding them on top of the view. The cocos layer is always at the bottom. You can add the view to the root view controller, but you'll take a performance hit.
You're going about this in the wrong way anyway. Put your button in a CCLayer subclass with a CCColorLayer background and add that to your running scene. In your case: self.
My Learn Cocos2D book (2nd Edition) has a chapter about UIKit integration that explains how you can place UIKit views in front of and behind the Cocos2D GL view while allowing all views (front views, cocos2d view, back views) to respond to touch events.

How to show modal in cocos2d game application?

I want to know how to show modal view in cocos2d? Any one can help me?
Thanks before. Regards. :)
I use this code for presenting a GKLeaderboard within cocos2d.
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
UIViewController *container = [[UIViewController alloc] init];
[container setView:[[CCDirector sharedDirector] openGLView]];
[container setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
leaderboardController.leaderboardDelegate = container;
[container presentModalViewController: leaderboardController animated: YES];
This will do what you want. Don't forget you need to release the UI objects when your done with them.