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.
Related
I programmatically instantiate a UIViewController from a xib, add it as a child VC to an existing main view, then add the child VC's view (which contains a button) to my main view. The view with the button displays just fine, but when I press the button, the app crashes with an "unrecognized selector" message.
I created the XIB by creating a custom subclass of a UIViewController ( File - New - Cocoa Touch class, selecting a subclass of UIViewController, and asking Xcode to also generate the XIB file). I then placed a button on that XIB, and hooked it up to the newly created UIViewController subclass. The XIB file's owner is set to the name of the new class.
So it looks to me like the ButtonPushed action message doesn't get send to my custom UIVC, and is going instead to the generic UIViewController - which rightly doesn't understand the ButtonPushed message.
How do I make sure that the action message sent when the button is pressed in fact goes to my custom UIViewController?
This is the code in my awakeFromNib method for the main view (main view is from Main.storyboard):
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:#"ButtonVC" bundle:nil];
vc2.view.frame = CGRectMake(90, 140, 50, 200); //dont obscure the main view completely.
[self addChildViewController:vc2];
[self.view addSubview:vc2.view]; //vc2.view has a button, which shows up fine
[vc2 didMoveToParentViewController:self];
I've managed to get the equivalent functionality by creating a storyboard just with the button, and programmatically loading that, then instantiating my buttonViewController, adding it and its view as a child VC to my main view. That works just fine, but it seems to me like I should be able to achieve this with "only" a XIB.
Try this:
UIViewController *vc2 = [[ButtonVC alloc] initWithNibName:#"ButtonVC" bundle:nil];
And also make sure that the class in your xib for the view controller is set properly (see my answer here)
(Xcode6-beta3, Swift, iPad, iOS8)
How can I create a splash page for an iPad app using a split view controller?
I've tried the straight-forward approach of drag n' dropping the little arrow to a new view controller, and setting up a button to segue to the split view controller on a touch up inside. This throws a memory error
I've also tried simply commenting out the following code from the application function in the AppDelegate, but I'm getting a
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [identifier length] > 0'
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.
// let splitViewController = self.window!.rootViewController as UISplitViewController
// let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
// splitViewController.delegate = navigationController.topViewController as DetailViewController
return true
}
I've even disconnect the Master-Detail view in Storyboard, so that all that should be loaded is the splash page alone, but it still crashes.
I am so stuck! Thanks for your help.
The problem you were having is related to the code in application:didFinishLaunchingWithOptions:
In that code the template access the "first" view controller defined in the Storyboard to get to the split view controller and set its delegate property. If you change the "little arrow" you are changing UIWindow's rootViewController property, and being of a different view controller, it crashes.
To solve that, the best way is:
create the storyboard as described (normal ViewController with a segue to the original Split VC)
comment out code in application:didFinishLaunchingWithOptions
create a UIView controller subclass for your newly added Scene
in that class, before the segue is done, insert this modified version of the code to set the Split View Controller's delegate property:
let splitViewController = segue.destinationViewController as UISplitViewController
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
splitViewController.delegate = navigationController.topViewController as DetailViewController
Working project here
This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
I am new to iPhone App development.
I got this error when I run my project
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<AboutViewController 0x91cc1d0> setValue:forUndefinedKey:]:
It happens when I try to navigate to another view controller called AboutViewController.
I defined the rightBarButton like this
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"About" style:UIBarButtonItemStylePlain target:self :#selector(showAbout)];
self.navigationItem.rightBarButtonItem = anotherButton;
The method showAbout is
- (void)showAbout{
AboutViewController *abvController = [[AboutViewController alloc] initWithNibName:#"AboutViewController" bundle:nil];
[self.navigationController pushViewController:abvController animated:YES];
[abvController release];
}
Also when I try to use presentModelViewController instead of navigationController, the compiler shows it is deprecated.
I found the problem, it was because of a button i used in the AboutViewController, i didnt declare the property for that button.
but can anyone tell me how to use ModelViewController to goto a new view in ios6, since when i use the method presentModelViewController, it shows a warning that it is deprecated
I think the problem is your AboutViewController, not in current view controller.
I guess your AboutViewController nib class is UIViewController class not AboutViewController class, try to change it to the right class. Click your nib file, and then click your file's owner, and then in the right section click third tab. You should see class in the top, change it to AboutViewCtroller.
Usually these types of error occur due to the problems with the outlets connected in xib.
Main scenarios:
View outlet is not connected in xib
Connected outlet's property is deleted from interface file
presentModelViewController is deprecated in iOS 6. Instead you can use presentViewController:animated:completion: for presenting the modalViews.
presentViewController:animated:completion:
Presents a view controller.
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
Parameters
viewControllerToPresent
The view controller being presented.
flag
Pass YES to animate the presentation; otherwise, pass NO.
completion
A completion handler or NULL.
Discussion
On iPhone and iPod touch, the presented view is always full screen. On
iPad, the presentation depends on the value in the
modalPresentationStyle property.
This method sets the presentedViewController property to the specified
view controller, resizes that view controller’s view and then adds the
view to the view hierarchy. The view is animated onscreen according to
the transition style specified in the modalTransitionStyle property of
the presented view controller.
The completion handler is called after the viewDidAppear: method is
called on the presented view controller.
Availability
Available in iOS 5.0 and later.
Declared In UIViewController.h
For more details check UIViewController Class
I would like to know how to correctly show a view programmatically. I will try to explain what i did so far:
The application has a storyboard with two view controllers. One of them has an identifier: " detailview". When i click on a button on the initial view controller i want to show the view controller with the identifier "detailview". Currently i'm using this code:
TI4ViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"detailview"];
UIWindow* window = [UIApplication sharedApplication].keyWindow;
[window addSubview:vc.view];
This works fine to show the view "detailview". But when i add a button on the detailview controller and add a touchdown event in the TI4ViewController(the view controller that's connected to "detailview") i'm getting an exception while clicking on this button.
I'm getting the following exception:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFType TestDown:]:
unrecognized selector sent to instance 0x6e0f670'
I'm using Xcode Version 4.3.2 (4E2002)
I'm not sure what i'm doing wrong here. I think the ViewController is released, but i'm not sure.
Instead of adding another view you can use segue. You can find an example here
Problem solved. I should have added the TI4ViewController as property of the initial view controller. Now it's removed from memory when you leave the function.
I made a multiview based application. My app has 3 views. The first is a disclaimer notice. When the user agrees it takes them to the main menu. From there, if they click a button, they will be taken to the respective views. One view is where the user can enter values (upon which a calculation is done). When I click the button to go to that view my app crashes and the following code gets highlighted. I followed this video tutorial.
[self presentModalViewController:second animated:YES]; along with the program received a SIGABRT message !
Checking the debugger showed me the following message: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<gainview 0x6a10d10> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label1.'
This is my full code:
code in the disclaimer view
-(IBAction)switchtoview2:(id)sender{
secondview *second = [[secondview alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
code in the main menu (i get the error when pressing the button in this view)
-(IBAction)swichtogain:(id)sender{
gainview *second = [[gainview alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES]; //debugger highlights this line !
}
When hitting the button it is supposed to go to another view where I have few buttons: UItextfields and few pickers.
Highly likely, you have a problem with one of your nib files, or a mismatch between nib definition and your classes.
In the nib associated to the controller that you are trying to show modally, check:
that all connections among outlets and objects are correct;
that the class identity of you nib objects is the one you expect to be (specifically for your controller/file's owner);
that your Objective C classes have all their IBOutlets defined.
If you need more help, you should post some more code...