I am trying to do a conditional segue. But I get:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel length]: unrecognized selector sent to instance 0x763c8e0'
The design is, when I pressed a button, the app will retrieve some data from the internet using AFNetworking's AFJSONRequestOperation. If the request succeed, it will call another UIViewController from my current UIViewController. I did my conditional start segue using this method and below are my codes:
-(void) login:(NSString*)pinString{
NSString* urlString = [NSString stringWithFormat:@"%@%@%@", [super.serverResource getURL], [super.serverResource getRequestByKey:@"login"] ,pinString];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [MenuletJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[self performSegueWithIdentifier:@"login" sender:self];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
switch([response statusCode]){
case (403):{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Log in failed"
message:@"Log in denied, check your PIN."
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
break;
}
}
}];
[operation start];
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SettingViewController *settingVC = (SettingViewController*)[storyboard instantiateViewControllerWithIdentifier:@"SettingViewController"];
[self presentViewController:settingVC animated:YES completion:nil];
}
And I get the exception above after "ViewDidLoad" excuted in SettingViewController. If I don't use conditional segue, and simply ctl drag from the Button to SettingViewController on IB, everything works fine... please give me some suggestion... I am really out of ideas...
Below are my code from SettingViewController:
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
//StringResources* resource = [[StringResources alloc]init];
[self.titleLabel setText:[super.stringResource getStringByKey:@"screen_setting_title"]];
[self.createOrderLabel setText:[super.stringResource getStringByKey:@"screen_setting_create_order_label"]];
[self.refreshMenuLabel setText:[super.stringResource getStringByKey:@"screen_setting_refresh_menu_label"]];
[self.tableNumberLabel setText:[super.stringResource getStringByKey:@"screen_setting_table_number_label"]];
}
Actually, I didn't put much thing in SettingViewController, all I did was programatically setting some label. And I put breakpoint on each setText, and they all executed without error. So the exception must happened after ViewDidLoad...
This is where the error occur:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); //error occur here
}
}
Solved... Turn out Segue handle everything. All I need to do is setup a generic segue. and once I called [self performSegueWithIdentifier:@"login" sender:self], everything works perfectly. Thank you everyone... (overriding prepareForSegue will only cause a problem...)