我正在尝试做一个有条件的segue。但我得到:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel length]: unrecognized selector sent to instance 0x763c8e0'
设计是,当我按下按钮时,应用程序将使用 AFNetworking 的 AFJSONRequestOperation 从互联网检索一些数据。如果请求成功,它将从我当前的 UIViewController 调用另一个 UIViewController。我使用这种方法做了我的条件启动segue ,下面是我的代码:
-(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];
}
在 SettingViewController 中执行“ViewDidLoad”后,我得到了上面的异常。如果我不使用条件segue,只需ctl从按钮拖动到IB上的SettingViewController,一切正常......请给我一些建议......我真的没有想法......
以下是我来自 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"]];
}
实际上,我并没有在 SettingViewController 中放太多东西,我所做的只是以编程方式设置一些标签。我在每个 setText 上都设置了断点,它们都执行没有错误。所以异常一定是发生在 ViewDidLoad 之后...
这是发生错误的地方:
#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
}
}
解决了...原来Segue处理一切。我需要做的就是设置一个通用的segue。一旦我调用 [self performSegueWithIdentifier:@"login" sender:self],一切正常。谢谢大家...(覆盖 prepareForSegue 只会导致问题...)