I'm using Objective-C, I want to copy an array for another view controller and push it. Here is my code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"comment"]){
commentViewController *vc = segue.destinationViewController;
vc.comments = [[NSArray alloc]initWithArray:comments];
}
}
But it doesn't work. I got this in Xcode:
2015-12-06 16:27:45.802 net[1244:29117] -[UIViewController setComments:]: unrecognized selector sent to instance 0x7ff8d34eb720
2015-12-06 16:27:45.807 net[1244:29117] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController setComments:]: unrecognized selector sent to instance 0x7ff8d34eb720'
Someone can help me?
Select your destination view controller in the storyboard. And in the identity inspector make sure that your destination vc is your custom class as seen in the pic.
Related
I have an app which has a sidebar menu (a UITableView) with different rows that are connected separately with the main view controller with a (push) Segue.
Only one of this doesn't work, so when I tap on it I recieve this message:
**** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainTabBarController topViewController]: unrecognized selector sent to instance 0x14880ce00'terminating with uncaught exception of type NSException*
In the SideBarViewController this is the part of the code that causes the crash:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(#"[segue identifier]: %#",[segue identifier]);
if ([[segue identifier] isEqualToString:#"sync"]) {
MainViewController *mainViewSync= (MainViewController *)[[segue destinationViewController] topViewController];
mainViewSync.sync = 1;
}}
How can I fix That?
I have the following code:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController performSegueWithIdentifier:#"push_display_incomming_call" sender:self];
This shows me the ViewController I want to see correctly. But now I want to change the property's value of the ViewController is being Segue before it's shown, I'm Trying the following with no success.
incommingCallViewController *mainController = (incommingCallViewController*) tabBarController;
mainController.name.text = #"Eddwn Paz";
This is the stacktrace from xCode Console:
2014-07-10 16:46:09.413 mobile-app[9354:60b] -[OptionsTabBarViewController name]: unrecognized selector sent to instance 0x17552540
2014-07-10 16:46:09.414 mobile-app[9354:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OptionsTabBarViewController name]: unrecognized selector sent to instance 0x17552540'
Assume that push_display_incomming_call segue presents IncommingCallViewController view controller as modal. So you should use code:
IncommingCallViewController *callVC =
(IncommingCallViewController *)tabBarController.presentedViewController;
callVC.name.text = #"Eddwn Paz";
Remarks:
You receive the error because you try to use tabBarController as instance of incommingCallViewController while it is instance of UITabBarController thus it does not have required name property.
I'm not entirely sure why I am getting this error. It occurs when I click the button on my FirstViewController:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController 1ButtonPress:]: unrecognized selector sent to instance 0x10954bbd0'
My FirstViewController has a button (1ButtonPress) which performs a segue with another ViewController which has a embed NavigationController (so in my storyboard, the segue is from FirstViewController to the NavigationController). On this segue, some data is transferred to the other ViewController by:
First.m
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"abc"]) {
UINavigationController *navController = [segue destinationViewController];
SecondViewController *BVC = (SecondViewController *)(navController.topViewController);
BVC.BLLImg = [UIImage imageNamed:#"SomeImage.jpg"];
BVC.BLLTitle = #"SomeText";
}
}
The segue has the identifier "abc" in storyboard. Looking around it, I believe it has something to do with an incorrect class, but everything on first inspection looks fine. Any other reason why I would be getting this error?
Let's go through the error you saw. It says that an unrecognized selector was sent to an instance of FirstViewController.
From what I deduce, you hooked up your button to your view controller, and removed the implementation from your view controller later, assuming that it'd remove the connection you earlier created from your button to your view controller. Unfortunately, that's not how it works. You need to remove the connection from the button too.
To do that, right click on your button in the storyboard, and remove the connection which says 1ButtonPress:.
Side note: You're doing too much for a beginner to understand. Please try going through the Cocoa world step by step. Also, read up this article to learn about how to name your methods and variables in a more easy-to-understand way.
Right-click the 1ButtonPress button in your Storyboard. Remove the action to 1ButtonPress:.
my code is breaking on the segue. the segue was modal at first , i tried to change it to push but its still not working my code is the following :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([[segue identifier ] isEqualToString:#"detailLoanSeg"]){
detailLoan *theController=[segue destinationViewController];
theController.time=_time;
theController.cuurLoan=_cuurLoan;
theController.currName=_currName;
}
}
and the error in xcode is :
014-05-07 04:38:11.257 LoanCalc[1561:a0b] -[UIViewController setTime:]:
unrecognized selector sent to instance 0xa05f1f0
2014-05-07 04:38:11.266 LoanCalc[1561:a0b] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[UIViewController setTime:]:
unrecognized selector sent to instance 0xa05f1f0'
It looks like, in storyboard, you forgot to indicate the custom class of the destination view controller. In storyboard, select that destination VC, click the third inspector from the right and set it's Custom Class to "detailLoan" (which violates class naming convention).
The error is that your destination vc is a generic UIViewController, which naturally doesn't implement the setTime: method.
Are you sure the destination class is your View Controller and not a UINavigationController? Put a breakpoint and check what theController class is. Also make sure that the view controller in the Storyboard has its class set from the default UIViewController to your custom subclass. It's almost certainly one of those two issues.
The gist of what I'm trying to do is set the value of a label on the window I'm segueing to the text that the user entered on the previous window.
The user segues by clicking "Read", which segues them.
Here's my prepareForSegue method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
ReadingViewController *destination = segue.destinationViewController;
destination.textToRead = self.textInput.text;
}
textToRead is just an NSString object that holds the text that the user enters. (This text is then set as a label with the viewDidLoad method.)
The window that is segued to is set as a different view controller as expected (ReadingViewController) and I created the segue by control-dragging from the "Read" UIButton to the next window.
I can't seem to figure out what the problem is. Here's the error it gives:
2013-03-13 19:00:08.119 Project Lego[1523:c07] -[UINavigationController setTextToRead:]: unrecognized selector sent to instance 0x894d230
2013-03-13 19:00:08.122 Project Lego[1523:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setTextToRead:]: unrecognized selector sent to instance 0x894d230'
*** First throw call stack:
(0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0x2949 0x45bb87 0x45bc14 0x10e3705 0x172c0 0x17258 0xd8021 0xd857f 0xd76e8 0x46cef 0x46f02 0x24d4a 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1bec7e3 0x1bec668 0x13ffc 0x244d 0x2375 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb)
If you want to access the view controller embedded in a navigationVC, do something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *nav = (UINavigationController*)segue.destinationViewController;
ReadingViewController *destination = [nav.viewControllers objectAtIndex:0];
destination.textToRead = self.textInput.text;
}
Your segue is referencing the UINavigationController, not your viewcontroller class. Check your Storyboard to make sure the segue is connecting the right controllers.
You seem to be setting textToRead on the Navigation controller. I am assuming you want to set this in the view controller. If so you need to
if ([segue.destinationViewController
isKindOfClass:[UINavigationController class]])
{
mvc = (ReadingViewController *) [segue.destinationViewController topViewController];
mvc.textToRead = self.textInput.text;
} else {
ReadingViewController *destination = segue.destinationViewController;
destination.textToRead = self.textInput.text;
}