I am displaying a modal view controller from an NSObject.
I call presentModalViewController:animated on self.sender which is another view controller. The view controller displays fine, but when I push a button in the view, I get the following error:
-[__NSCFType buttonCancelPressed:]: unrecognized selector sent to
instance
This is how I display the modal view controller from my NSObject:
FBComposeViewController *composeViewController = [[FBComposeViewController alloc] initWithNibName:#"FBComposeViewController" bundle:nil];
[self.sender presentModalViewController:composeViewController animated:YES];
The button is hooked up to a selector in FBComposeViewController using Interface Builder.
Does anyone have an idea why I might be getting this error?
The problem is probably the binding in FBComposeViewController.xib. What is the target-action for the cancel button set to?
Why are you using self.sender? Assuming sender is a UIButton object.
Assuming, this line of code is written in a Controller Class, use:
[self presentModalViewController:composeViewController animated:YES];
Related
I've already spent the whole day in an issue and did not find a solution yet. I have a UITabBarViewController and I am trying to fire off a modal segue from one of its tabs. I've already created the view I want to segue to, created the segue itself (from the tab's view controller to the target's view controller) and the identifier. In order to test my segue I created a UIButton in my tab and wrote the following code on its action:
[self performSegueWithIdentifier:#"showProductInfo" sender:self];
The modal segue worked fine. But if I try to write the same code to be performed somewhere else (inside a specific method that is called after I receive a web service response) the segue simply does not work. I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'showProductInfo''
This is driving me crazy! Any help is more then welcome.
Editting:
Some additional findings:
If I take off the performSegue from the method I am currently using (which by the way is called by DidFinishLoading) and put it on ViewDidLoad the segue is performed successfully.
Thinking that it could be a thread related issue I included the performSegue inside a dispatch_async(dispatch_get_main_queue()... But the error is the same !
If your destination viewcontroller is inside a navigationcontroller, then take a look at this question:
http://stackoverflow.com/questions/8041237/how-to-set-the-delegate-with-a-storyboard
Furthermore, from the error it looks like the segue you are trying to perform is not attached
to the viewcontroller you are starting from. So,Try to remove the seque and drag it from the
viewcontroller.
The current view controller must have been loaded from a storyboard. If its storyboard property is nil, perhaps because you allocated and initialized the view controller yourself, this method throws an exception.
Make sure you have Storyboard ID for your destination VC (in this example myViewController).
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"myStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:#"MyController"];
[self.navigationController pushViewController:myViewController animated:YES];
I have a tab-based app. The app launches with FirstViewCOntroller. I want to display modalview when same tab item First View is clicked.
I am trying to add code in app delegate in tab bar's didSelectViewController method, but I am getting error as unrecognized selector is sent to an instance. Also, warning is displayed as presentViewController method not found.
I am adding code in foll. way:
ModalViewController *modalView = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
modalView.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:modalView animated:NO completion:NULL];
[modalView release];
Please help.
Thanks in advance
PresentViewController is a method defines in viewcontroller class, so you will have to call it from the Viewcontroller class. Since you have written this code in app delegate where self is not a viewcontroller.
So I would suggest you to use FirstViewcontroller class to execute this code
I have a cancel button, when i press cancel button then i pop my current viewcontroller. Before popping my controller, i want to access one member (which is a class Student) of previous view controller. So i am doing this way:
StudentProfileViewController *controller = (StudentProfileViewController*)self.parentViewController;
NSLog(#"%#", controller.student);
My app crashes on line NSLog, error is this:
[UINavigationController student]: unrecognized selector sent to instance 0x6865180
Strange part is its says "[UINavigationController student]" but my controller is UIViewController.
Can anyone shed a light on this. I know some silly mistake is being done.
Thanks
The parentViewController would return the controller you are looking for only if you had presented modally from that view in the first place. It looks to be that you are trying to reference the previous controller in the stack, not the presenting view.
In your case, the parentViewController is the navigationController if that is how you presented. You are casting it to the controller class you wish it to be but that doesn't make it so.
More appropriate method would be to have passed the object you wish to reference in the init method or, most preferably, make a delegate method to tell the former view when this controller is complete, then let the former view react as intended.
I'm trying to navigate from a UIViewController to a UITableViewController with this action button. Obviously I'm doing something wrong so it's missing the UINavigationController linked to the UITableViewController in my storyboard. Or something like that. This code displays the TableView when I press the button, but navigation bar is missing so there's no way of going back and if I swipe through the tableview the app crashes.
-(IBAction)nextButtonPressed:(id)sender{
ResultsTableViewController *nextController = [[self storyboard] instantiateViewControllerWithIdentifier:#"Results Controller"];
nextController.objectsArray = resultObjectsArray;
[self presentModalViewController:nextController animated:YES];
[nextController release];
}
Should I link the UINavigationController with the UIViewController instead of the UITableViewController, will that work? Or should I target the code above for the UINavigationController instead? How to do this simple thing? Thanks.
EDIT 1:
Adding the Navigation Controller to the UIViewController instead and push to the TableView with it like this:
[self.navigationController presentModalViewController:nextController animated:YES]
didn't solve the issue. It still crashes when swiping.
EDIT 2:
If I do like this:
[self.navigationController pushViewController:nextController animated:YES]
it crashes once the tableview is visible on screen. I get a glance at the navigation bar with "back" button now though. This is crash report from this:
-[__NSCFType isViewLoaded]: unrecognized selector sent to instance. Rødvinsguiden[318:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType isViewLoaded]: unrecognized selector sent to instance 0x6b9d2e0'
you're forgetting to push WITH the navigationController of your current view, instead your just pushing the new viewController without it.
[self.navigationController presentModalViewController:nextController animated:YES]
When I try to push a view controller to my UINavigationController I get a NSInvalidArgumentException thrown with the error message "unrecognized selector sent to instance". But this only happens when I name my UINavigationController ivar anything other than "navigationController". Is there a reason for this?
Not sure how your code is structured, but every UIViewController has a navigationController property. (See http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html)
So, [self navigationController] is returning the property from the current view controller (whatever self is), not what you've named in your AppDelegate.