As I'm very new to IOS development, I don't really know all the mechanisms that are to be used while developing iPhone apps.
Here, what I'm trying to do is to call another controller after performing a segue.
The context :
I have my first page, which basically consists on a login page, with a user/password system. I created a segue which is called by clicking on the Submit button. Here's the code :
- (IBAction)Connect:(UIButton *)sender
{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"passwordsample", @"usernamesample",
nil];
if ((![[dict allKeys] containsObject:TFLogin.text])) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Login or password incorrect" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
NSLog(@"Connection Not OK");
}
else {
[self performSegueWithIdentifier:@"LoginSegue" sender:sender];
NSLog(@"Connection OK");
}
}
And here's the prepareForSegue function :
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
HomeController *home = (HomeController *) segue.destinationViewController;
home.sentLogin = TFLogin.text;
}
The fact is that, when I click on the Submit button (on the login page), the logs show me that the user is correctly found, and then I get the error as following :
2012-04-30 11:24:44.630 AppName[1066:f803] -[UINavigationController setSentLogin:]: unrecognized selector sent to instance 0x6d73c30
2012-04-30 11:24:44.630 AppName[1066:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setSentLogin:]: unrecognized selector sent to instance 0x6d73c30'
Here's the storyboard :
The second NavigationController is to be replaced with a Tab Bar Controller. But for some testing, I've put this one.
Could someone please guide me, telling me what I'm doing wrong and/or sending me some recent guides on storyboarding and navigation ?
Thanks a lot !
By the looks of the error, it seems like segue.destinationViewController isn't what you think it is. Sounds like you have a navigation controller in the mix.
It's a bit difficult to diagnose without your storyboard but try:
UINavigationController *nav = (UINavigationController*)segue.destinationViewController;
HomeController *home = (HomeController*)nav.topViewController;
If that doesn't work, you may want to place a breakpoint on the second line and take a look at the nab controller to see where the HomeController is on its stack.
ProjectManagementViewController * projectManagementView = [[ProjectManagementViewController alloc] initWithNibName:@“ProjectManagementViewController”bundle:nil];
[self.navigationController pushViewController:projectManagementView animated:NO];
you can do it like in ios5:
[self performSegueWithIdentifier:@"your-segue-name" sender:self];
you will create a segue from one of your view to another but not through buttons or anything else , just drag from your first-view to second-view your segue and when your process done just call the code above.
hope this helps..
edit : you need to give a name to your segue in your storyboard just clicking on it and then naming in on the right-side inspector..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.