"Unrecognized selector sent to instance" error - objective-c

Part of my AppDelegate code is:
UITabBarController *tabBarController
= (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController
= [[tabBarController viewControllers] objectAtIndex:0];
PilotosViewController *playersViewController
= [[navigationController viewControllers] objectAtIndex:0];
playersViewController.drivers = players;
But I get this exception:
-[UIViewController viewControllers]: unrecognized selector sent to instance 0x6a75770
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController
viewControllers]: unrecognized selector sent to instance 0x6a75770'
Where is the mistake?

I met the same issue, because I followed the steps by the author, but
UINavigationController *navigationController
= [[tabBarController viewControllers] objectAtIndex:0];
this is what which made the crash, because navigationController is not at index=0,
I did exchange the locations of the two tab bar items, then it works.

You need to make sure that you connect things properly in your XIB or storyboard. The exception is showing you that the object is of type ViewController when you send [tabBarController viewControllers] and you were expecting a UITabBarController. That's why you're getting '-[ViewController viewControllers]:. Make sure that your root view controller really is a tab view controller.

You are obviously receiving different type of object on index = 0.
If you are using storyboard go there and open Navigator > find specific controller > see Relationships. This order can be used when referencing its viewControllers collection.

Related

ECSlidingViewController not First View

My application start with a view thats not use ECSlidingViewController, and then have a button to another that uses it.
In switching the views using Storyboard Segue, but I'm getting error.
What should I add to btnGoSecondView to load ECSlidingViewController properly?
Code:
-(IBAction)btnGoSecondView:(id)sender {
[self performSegueWithIdentifier:#"SecondViewShow" sender:self];
}
Error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
i think you should make some initialview first, and make that view became initial view controller and make an identifier for every each view controller.
something like this ..
self.viewcontroller = [storyboard instantiateViewControllerWithIdentifier:#"home"];
Based on the error you're getting an object is trying to be inserted into a mutable array but it hasn't been initialised. Where is the exception thrown in your code?
Try work out where the array is being accessed and why it's null. The NSMutableArray may not have been initialised in which case you'll need to initialise it.
NSMutableArray *arrayName = [NSMutableArray new];
Another thought: Before the ECSlidingViewController is presented I think you need to set it's topViewController. You could add it in -prepareForSegue:sender: or in the viewDidLoad of the viewController to be presented.
Something like this perhaps:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)segue.destinationViewController;
slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"FirstTop"];
}

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.

add SplitViewController view trouble under iOS5

When I trying to add SplitViewController to view hierarchy application terminates with:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] must not be called with nil.'
SplitViewController *viewController = [[SplitViewController alloc] init];
[self.window addSubview:viewController.view];
Where SplitViewController subclass of UISplitViewController
I don't understand which popover it means.
This trouble appear only on iOS5.
After initializing viewController, you should set its viewControllers with viewController.viewControllers = [NSArray arrayWithObjects:leftNavigationController, rightNavigationController, nil];
Else, your SplitViewController does not know what to display on the left and on the right.
Pay attention also to the delegate.
Please check if this helps :)

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController modalTransitionStyle]:

i used the following code to display my image picker controll.
IPopoverController *popoverController = [[[UIPopoverController alloc] initWithContentViewController:myImagePicker] retain];
[self presentModalViewController:popoverController animated:YES];
but there is a error that shows
working with image view[14335:207] *
Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'-[UIPopoverController
modalTransitionStyle]: unrecognized
selector sent to instance 0x6415950'.
can any one help me please.
You need to use this...
[popoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Or one of the other present methods, check the Apple docs.
The short answer is that you cannot use UIPopoverController to present it as a modal one. Please try using UIViewController instead.
You probably will need to subclass it and either load it from some nib or create its view content manually in loadView method.

Touchupinside and simple viewController question

I've got a very simple viewController question .
I've got a main view with 2 buttons, upon touchupinside of a button I would like to load a new view Controller ( a table view ) .
I've created a new viewController with its nib file .
Created an IBAction like this that I've linked the button to in IB :
- (IBAction)displayVin {
UIViewController *vinController = [[UIViewController alloc] initWithNibName:#"vinController" bundle:nil];
[self.navigationController pushViewController:vinController animated:YES];
[vinController release];
}
It's not doing anything therefore I must be forgetting something, but what ? should I declare this newViewController somewhere else ? It's compiling and executing fine with no error message .
UPDATE:
I'm now using this :
- (IBAction)displayVin:(id)sender {
NSLog(#"here");
UIViewController *vinController = [[UIViewController alloc] initWithNibName:#"vinController" bundle:nil];
[self.navigationController pushViewController:vinController animated:YES];
[vinController release];
}
But it's crashing with this error when I press the button :
[displayVin]: unrecognized selector sent to instance 0x8d03000
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[displayVin]: unrecognized selector sent to instance 0x8d03000'*
Should I be declaring something somewhere else , or "should" that bit of code be enough ?
Start by using NSLog() to determine if you're actually inside the displayVin() routine. Button events send a parameter to the acion, so you should probably declare it as -(IBAction)displayVin:(id)sender instead of just -(IBAction)displayVin.
For your updated code, you might have to reconnect the IBOutlet in the IB file. It looks like it's still calling the [viewController displayVin] method (without arguments), instead of the [viewController displayVin:]