I try to load a loginView in my app delegate but it only shows the original white splash which sais something like "Welcome to universal app".
I am quite puzzled.
I have created a loginView.xib. Files Owner's class is LoginViewController.h. The view is linked to Files Owner.
I load the view like this in applicationDidFinishLaunchingWithOptions
LoginViewController *loginVw = [[LoginViewController alloc] init];
[self.window addSubview:loginVw.view];
[self.window makeKeyAndVisible];
Any idea what I am missing?
The designated initialiser for a UIViewController backed by a XIB is - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle.
Your code should look more like
LoginViewController *loginVw = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
Documentation and sample code is your friend in this case.
replace
LoginViewController *loginVw = [[LoginViewController alloc] init];
with
LoginViewController *loginVw = [[LoginViewController alloc] initWithNibName:nil bundle:nil];
so the LoginViewController actually uses your .xib
Related
self.rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[self.window addSubview:self.rootViewController.view]; //App will not crash without this line
self.navigationController = [[UINavigationController alloc] initWithRootViewController: self.rootViewController];
[self.window addSubview:self.navigationController.view];
I run it in the simulator and it crash, why?
Error message:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
reason: 'adding a root view controller <RootViewController: 0x6871620> as a child of
view controller:<UINavigationController: 0x6a86dc0>'
still have no idea
yours logic is wrong. Either add rootViewController or add navigationController as window's subview. You can't add two viewcontrollers at the same time. Here your navigationController will overwrite your rootviewcontroller. If possible then add your rootviewcontroller into navigationController or add navigationController into rootviewcontroller
Since You are setting RootViewController nib name to nil i hope you are managing your view in RootViewController.m inside method -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil or some other way.
to fix your error message you have given, change your posted code following way
self.rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController: self.rootViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
You are not specifying your problem clearly,so please add error message what you got on the console.Without error message we are unable to tell where the problem occur.Any how it crashes due to nibfile name,you specifying nib file name as nil.Please specify nib file name. Try this code once.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
self.navigationController=[[UINavigationController alloc] initWithRootViewController:self.rootViewController];
self.window.rootViewController = self.navigationController;
// [self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
I hope this code will solve your problem
I created a game in Xcode and now I decided to add a menu to it, the menu is the first loading view so I changed
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
to:
self.viewController = [[[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil] autorelease];
now the view where my game is, is: ViewController.m and from the menu I go there with:
-(IBAction)gogame:(id)sender {
UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Game animated:YES];}
Because I needed to give the ViewController.m a name I changed in .h and .m:
#interface ViewController to #interface GameViewController in .h
and #implementation ViewController to #implementation GameViewController in .m
Now I made the button in menu "gogame" run it, and when I click the button it goes from the menu to a black screen, it doesn't crash or anything It only shows the status bar and a black screen. the only issue that xCode gives me is in app delegate: incompatible pointer types assigning to 'GameViewController *' from 'MenuViewController *'.
I do not know why this is not working And I hope someone could exlain me and tell me how to solve this. thanks
UIViewController alone is nothing useful, it's provided to have behavior added to, so in your method:
Here's your version of this method:
-(IBAction)gogame:(id)sender {
UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Game animated:YES];
}
and it is doing exactly what you are telling it to, present a framework provided UIViewController. You haven't added any extra behavior or a custom view.
I'm having trouble totally interpreting your current code setup, but it sounds like your new class GameViewController is what you want to show, so change it to:
-(IBAction)gogame:(id)sender {
GameViewController *Game = [[[GameViewController alloc] initWithNibName:#"GameViewController" bundle:nil] autorelease];
[self presentModalViewController:Game animated:YES];
}
Based on your renaming/refactoring of the class name, I wasn't sure what the name of your xib file for the controller is. Is it the original "ViewController" or did you also update that to "GameViewController" (like you should)?
Regarding the warning, where are you creating and assigning a GameViewController?
I've tried every solution on Google and nothing seems to work. So far I've implemented a UINavigationController with the App Delegate, now all I want to accomplish is changing to the WebViewController by clicking the UIButton I've created in the interface builder, but the button doesn't seem to do anything when I run the application. Keep in mind that I want it to push to my WebViewController view.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
ViewController.m
- (IBAction)createFile:(id)sender {
WebViewController *webViewController = [[WebViewController alloc] initWithNibName:#"WebViewController" bundle:NSBundle.mainBundle];
[self.navigationController pushViewController:webViewController animated:YES];
}
Note: In the interface builder I've already connected createFile to the button.
I understand that this is usually something that comes known as super easy but for some reason I've just never gotten it to work. Thanks in advance.
EDIT: I added the retaining property, sythesized it and added to my code in the ViewController.m file:
WebViewController *webViewController = [[WebViewController alloc] initWithNibName:#"WebViewController" bundle:NSBundle.mainBundle];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:webViewController];
[self.navigationController pushViewController:webViewController animated:YES];
But now the app crashes on the button click and returns with a SIGABRT: "Pushing the same view controller instance more than once is not supported (WebViewController: 0x1ed70e80)"
give this a try
-(IBAction)createFile:(id)sender{
WebViewController *webViewController = [[WebViewController alloc]
initWithNibName:#"WebViewController" bundle:nil];
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:webViewController animated:YES];
}
One thing i noticed is that you are not retaining your navigationController in the appDelegate. So what may be happening is that your the navigationControllers view may be present and retained (from the all to addSubView) but the navigation controller may have been deallocated.
in your AppDelegate try making the Navigation Controller a retaining property
#property (nonatomic, strong) UINavigationController *navigationController
in your .m file
#synthesize navigationController
and then
Edit: Updated for pushing a view controller
WebViewController *webViewController = [[WebViewController alloc] initWithNibName:#"WebViewController" bundle:NSBundle.mainBundle];
[self.navigationController pushViewController:webViewController animated:YES];
Hihi all,
I am pretty new in iPhone dev. I have follow some tutorial and created a tabbar application. Below is the code in the appdelegate implementation:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
UIViewController *viewController2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
Then set the title and the image for the tab in each of the controller implementation.
My problem is that, example, in my viewController1, I need to navigate to viewController3, when I use presentModalViewController method to push the viewController3 in, the tabbar at the bottom will be disappeared.
While I tried to use the app delegate to refer to my tabBarController, and use tabBarController.navigationController pushViewController method, my viewController3 is not being pushed, and seems nothing happens.
I have tried to follow a few tutorial, but it's all required to drag in the navigationcontroller into the MainWindow.xib, which, in the xcode 4, MainWindow.xib doesn't exist anymore. How can i create the navigationcontroller from code so that the app can navigate between different view without hiding the tabbar?
Any comment is very much appreciated! Thanks in advance!
:)
If you want to use a navigation controller, you need to create a navigation controller. Since you're not using a XIB, you'll have to create it manually.
Since you want the tab bar to remain visible when you present viewController3, you need to make the navigation controller a child of the tab bar controller.
UIViewController *viewController1 = [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:
navController1,
viewController2,
nil];
Then when you want to present viewController3, do this:
// in some method of viewController1
[self.navigationController pushViewController:viewController3 animated:YES];
I am not very Sure but have you tried this??? Actually i am going to use XCode 4 soon, i am still using 3.2.8 version:-
WebViewController *viewController = [[WebViewController alloc]initWithNibName:#"WebViewController" bundle:nil];
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:viewController animated:YES];
[viewController release];
See in this also the Tab bar will be removed when you navigate to your 3rd screen, you have to provide the navigation bar to come back.
Hope it helps.. :)
In my view controller, I have:
- (void)viewDidAppear:(BOOL)animated
{
LoginViewController* lvc = [[LoginViewController alloc] init];
lvc.delegate = self;
[self presentModalViewController:lvc animated:NO];
[lvc release];
}
However, this doesn't show up. What might be the possibilities? I tried to do a NSLog inside and it prints out.
Here's how I wire it up:
This is a UISplitView application where I put this code inside a RootViewController
Did you link the View to the LoginViewController in IB? That's the most common issue...
If logging your navigationController does not give you nil, then try the following:
[self.navigationController presentModalViewController:lvc animated:NO];
You are probably creating your LoginViewController correctly. Try replacing:
LoginViewController* lvc = [[LoginViewController alloc] init];
with
LoginViewController* lvc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
You need to specify which NIB to load the view controller from.
It turns out that I have a conflicting code in my UIDetailView, which is trying to do another popup...