I have this problem, however none of the information I can find on this forum or the internet in general seems to be able to help me.
There seem to be two places where this error can come about:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
The last argument in UIApplicationMain
returns an NSString
value of the class of my AppDelegate
. This is therefore working fine.
2.AppDelegate.m - there is an "older" way of setting the root view controller which is like this:
[self.window addSubview:rootViewController];
However, in my app it has already been updated to:
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
So none of the current information on the internet works. It is slightly more puzzling as my colleague can get it to work on his computer perfectly fine - he was the one that sent me the app source code so all the settings and code should be exactly the same.
I am trying to launch this in the simulator. It is built against iOS 5, but I'm trying to run it on the iOS 6.0 simulator.
I have the latest XCode (4.5.1).
Is there any reason this would be happening? And how can I rectify it?
Many thanks
Tom
Accessing the Root View Controller But it's easy to do. The root view controller is simply the view controller that sits at the bottom of the navigation stack. You can access the navigation controller's array of view controllers through its viewControllers property.
plist file → Application Scene Manifest property → Scene Configuration → item 0 and get rid of the property Storyboard Name by clicking the icon that has a minus in the circle next to it. ► Run the app and you will see the black screen and let's change that by setting a new root view controller.
The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller's view as the content view of the window.
I ran into exactly the same thing trying to add a UITableView to a single-view app. Instead, create a default Master-Detail Application project (file->new->target->...) and see the AppDelegate's implementation of didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MDMasterViewController *masterViewController = [[MDMasterViewController alloc] initWithNibName:@"MDMasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Rather than directly setting your view controller as the window's rootViewController, you need to create a navigation controller init'ed with your view controller for initWithRootViewController, then set that nav controller as the window's rootViewController. (Notice you also have to squirrel away that nav controller in a property so it doesn't get destructed).
Just change this:
[window addSubview:tabBarController.view];
to this:
[window setRootViewController:tabBarController];
Or whatever was in the addSubView:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With