Multiview application crash - objective-c

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...

Related

EXC_BAD_ACCESS after dismissViewControllerAnimated:completion:

I'm struggling to find what’s going wrong with my code. I’m trying to dismiss a UITableViewController using delegate but getting a EXC_BAD_ACCESS.
The UITableViewController is called (modal segue) from the root view controller of my application. When the rootViewController try to dismiss the UITableViewController everything seems to be all right because the rootViewController view is presented but after a milisecond the error arise.
- (void) dismissFormAViewController: (FormAViewController*) vc{
[vc dismissViewControllerAnimated:YES completion:^{
NSLog(#"complete.");
}];
}
I can see the string Complete on my console.
typically this means that you are accessing some memory that isn't a valid object anymore,
to debug turn on zombies in your run scheme, this will give you at least the class that is being accessed... Then if it is not obvious, you can back track with malloc logging

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.

Changing views works in viewDidLoad but not on a button click IBAction

I want to open up a new view with the identifier AddSourceViewController when a button is clicked. I'm using the following code to do so:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"AddSourceViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
When used in viewDidLoad on an initial view, this code works perfectly and opens up the additional view. However, I have added an IBAction to a button on the initial view and when I add the above code to attempt to open the new view on button click, I just get a Thread 1: breakpoint 5.1 6.1. How can I get this to work on the button action?
EDIT: Better error information below.
2012-11-23 16:33:40.399 Marketr[23454:c07] -[SecondViewController addSourceButton:]: unrecognized selector sent to instance 0x6e2f5c0
2012-11-23 16:33:40.400 Marketr[23454:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SecondViewController addSourceButton:]: unrecognized selector sent to instance 0x6e2f5c0'
Do you have a breakpoint set for your action method? Look on the left side next to the code of this method, to see if there is a blue arrow pointing towards the code.

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<AboutViewController 0x91cc1d0> setValue:forUndefinedKey:]: [duplicate]

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

presentViewController - view solid black, viewDid___ methods not called

...
SecondViewController *svc = [SecondViewController new];
[self presentViewController:svc animated:YES completion:NULL];
}
This code is exactly the same as what I used in another app, but here I'm using presentViewController rather than presentModalViewController
(completion:NULL makes them effectively identical. Same result, at least.)
Both attempts at creating a modal view are structured the same way. Those lines in the main view, a view controller in the Storyboard, and matching .h and .m files. The only difference is that here I want a programmatic trigger, so it's impossible to drag a segue and be done with it.
I have an object set to recognize a gesture and call the transition method. That's probably what's causing the problem (part of it, at least), but it is necessary.
Using a UIButton would be cheating. No deadline, no shortcuts.
EDIT: NSLog output shows something odd.
2012-04-05 10:41:12.047 MyApp[5962:707] <SecondViewController: 0x1d8c130>
2012-04-05 10:41:12.479 MyApp[5962:707] <SecondViewController: 0x1d8e360>
So I'm doing something stupid again that happens to have a very simple fix, right?
Edit again: presentViewController… was being called more than once. Fixed it. Still black, though.
Back to performSegueWithIdentifier:sender: instead of the much easier presentViewController:animated:completion:
Terminating app due to uncaught exception 'NSInvalidArgumentException", reason: 'Receiver … has no segue with identifier …'
I told it to perform a segue, but there isn't one in the Storyboard (I can't add one, there is no Storyboard Segues section under 'Connections inspector' for the object I'm attempting to use), so it crashes. This is normal behavior.
What I want is to have a modal view without needing to create a segue. I've done it, so I know it's possible.
All I need is a bit of help getting it to work.
.
performSegueWithIdentifier:#"Identifier" sender:nil NSSInvalidArgumentException
presentViewController:viewController animated:YES completion:NULL Empty View
Got it.
Replace the lines in the question with this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard"
bundle:nil];
SecondViewController *viewController =
[storyboard instantiateViewControllerWithIdentifier:#"SecondView"];
[self presentViewController:svc animated:YES completion:NULL];
Credit for this solution goes to IturPablo's self-answered question:
TabBarController, overwriting shouldSelectViewController to do a segue
Are you looking for performSegueWithIdentifier:sender:? The docs seem to match your description:
"you can call this method to trigger a segue programmatically, perhaps
in response to some action that cannot be specified in the storyboard
resource file"