App crashes when creating Universal app with multiple XIB and single View Controller - xcode4.3

I created a Universal window app in Xcode 4.3.3. Later I added one View Controller(UniversalRootViewController) class without XIB. Then I created two XIB files(RootViewController_iPhone, RootViewController_iPad) and then connect these iPhone XIB file RootViewController_iPhone to the UniversalRootViewController class: RootViewController_iPhone -> Select File's Owner and changed the class name in Identity Inspector as UniversalRootViewController and then connect the view as outlet to UniversalViewController and did the same thing for RootViewController_iPad.
In App Delegate , I added the following lines of code.
UniversalRootViewController *controller = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
controller = [[UniversalRootViewController alloc] initWithNibName:#"RootViewController_iPad" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window addSubview:navigationController.view];
}
else
{
controller = [[UniversalRootViewController alloc] initWithNibName:#"RootViewController_iPhone" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window addSubview:controller];
}
Also I added these two key-value pairs in UniversalApp-Info.plist
Main nib file base name : RootViewController_iPhone
Main nib file base name (iPad) : RootViewController_iPad
When I run this application, the app creates by displaying the following error message.
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
I connected XIB files properly to View Controller. I don't know why the app crashes. Please tell me the solution.

You will have to set the view outlet in the File's Owner to each view in the XIB file:
- Go to one of the XIB file (iphone for example) and drag with the left mouse button from the file owner to the top view below in objects. Select view.
- Do the same for the other XIB file

I solved my problem by removing the two key-value pairs of Nib files in Universal-Info.plist. Now the app works perfectly without any crash.

Related

Load custom viewcontroller from xib

Hello I have an OS X application with multiple windows and views.
Now i wanted to refactor some code and tried to load my custom viewcontroller through my generated xib file with follong method:
TestViewController* tableViewController =
[[TestViewController alloc] initWithNibName:#"TestView" bundle:nil];
TestViewController is a subclass of NSViewController. At this point everything is fine, (i hope) because i see no exception.
To get a bit more understanding of my code, here is the part that throws the error:
if (tableViewController != nil)
{
myCurrentViewController = tableViewController;
[myCurrentViewController setTitle:#"TestView"];
}
[[self window] setContentSize:[smallView frame].size];
[[[self window] contentView] addSubview:[myCurrentViewController view]]; //here is the error
I already tried things like check for files owner, main interface is MainMenu ...
Finally I found the solution for my problem.
My ViewController with Xib was generated by XCode and all files have the same name schema like TestViewController.h, TestViewController.m and TestViewController.xib.
All the examples i found reference the xib file with "TestView", so i thought xcode matches the correct viewcontroller with its view by adding the "Controller" ending to the xib name.
In my case i had to rename my xib file from TestViewController.xib to TestView.xib and i could load it with #"TestView".
Hth

Add a Storyboard in a existing XIB Project

I use in my project only xib files. Now i need a static tableview for a settings view. I want to combinied xib and one storyboard(for the tableview).
I add a storyboard with one viewcontroller in my projekt. After than i add a identifier(SettingsView) for this viewcontroller. the following code is executed when the button was pressed:
SettingsView *CustomViewController = [[UIStoryboard storyboardWithName:#"Storyboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"SettingsView"];
[self presentModalViewController:CustomViewController animated:YES];
My Application crashed when i push the setting button:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'SettingsView''
Please make sure that you added the StoryBoard ID as follows in the picture attached.
The storyboard and individual view controller that you are attempting to instantiate, names have match exactly. Otherwise, the rest of what you are doing is correct from what I can see.

Setting root view controller in didReceiveLocalNotification: results in black window

I know different versions of this question has been asked before but I'm really stuck here. I'm trying to get my app to push a new view from my app delegate when getting:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)localNotif {
And I put the following code in there:
MyViewController *myViewController = [[MyViewController alloc]init];
nvcontrol = [[UINavigationController alloc] initWithRootViewController:myViewController];
[nvcontrol.navigationBar setTintColor:[UIColor blackColor]];
self.window.rootViewController = nvcontrol;
and from this, I get a black view (which myViewController should not have) with a black navigation bar.
What am I doing wrong here?
As I've outlined above, you can use storyboard to set the initial view controller.
Note that if you have a view controller set up in storyboard and then you create a view controller in the application delegate, the view controller you created won't look like your one in storyboard. This is because you are making an instance of the CLASS, but the program has no way to associate this with your layout.

Adding login screen in front of tab bar in Xcode 4

I have read Adding login screen in front of Cocoa Touch Tab Bar Application for IOS but think the tab bar application code must have significantly changed in Xcode 4.
Steps I followed:
I created a new tab bar application
I created a new group called Login
Within Login I created a Login.xib file with the fields and button
I created a new view controller (.h and .m files) called LoginViewController
I clicked on the xib file and made sure it's files owner was set to LoginViewController
In LoginViewController.h and .m I created the appropriate IBAction for the login button and IBOutlets for the username and password fields and wired them up.
I went into the app delegate's didFinishLaunchingWithOptions to figure out how to change it to launch my .xib file first but stuck there.
I got it to work. Here's what I did:
self.window.rootViewController = self.tabBarController;
LoginViewController *loginViewController = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
[self.tabBarController presentModalViewController:loginViewController animated:YES];
[self.window makeKeyAndVisible];
return YES;

How to I navigate back to a previously loaded xib file?

In my app, I have three views. Originally, the appDelegate opened the xib file for the mainViewController, and the preset settings on my application template included a flipsideViewController, which would be shown when an information button was hit.
Later I decided to include another view controller and xib file, called CountySelectionViewController. The xib file has a button that opens the xib file for the mainViewController via the following:
MainViewController *controller = [[MainViewController alloc] initWithNibName:#"MainView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
Should I use the same thing to go back to the CountySelectionViewController as well as its xib? or is there a better way?
I believe what you're looking for is dismissModalViewControllerAnimated: -- http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/dismissModalViewControllerAnimated: