[英]perform segue throws error
我已经在目标 c 中实现了一些 Json 帖子,在我收到信息后,我尝试推送 segue 方法,但它抛出了这个异常
2015-06-25 00:08:33.807 BarApp[1446:109590]-[NSNull 长度]:无法识别的选择器发送到实例 0x37439830
2015-06-25 00:08:33.809 BarApp[1446:109590] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSNull 长度]:无法识别的选择器发送到实例 0x37439830”
这是我的代码
-(void) MakePost: (int)typePost {
NSString *mainUrl = @"http://url.com/barap/usuario.php";
NSString *post;
if(typePost == 0) {
post = [NSString stringWithFormat:@"?type=0&email=%@&password=%@",self.emailTextField.text, self.passwordTextField.text];
}else if(typePost == 1){
post = [NSString stringWithFormat:@"?type=1&fb_id=%@&nombre=%@&apellido_m=%@&email=%@&profile_picture=%@",fb_id, nombre, apellidoM, email, profilePictureUrl];
}
NSString *webPostUrl = [NSString stringWithFormat:@"%@%@", mainUrl, post];
webPostUrl =[webPostUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *postUrl = [NSURL URLWithString:webPostUrl];
NSData *userInfo = [[NSData alloc] initWithContentsOfURL:postUrl];
if(userInfo){
NSMutableDictionary *userResults = [NSJSONSerialization JSONObjectWithData:userInfo options:NSJSONReadingMutableContainers error:nil];
if (![userResults[@"id"] isEqualToString:@""]) {
[defaults setObject:userResults[@"id"] forKey:@"userId"];
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] valueForKey:@"userId"]);
这是我的代码分解的地方!
[self performSegueWithIdentifier:@"loginSuccess" sender:self];
if(typePost == 1){
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
}
}
}else {
UIAlertView* cError = [[UIAlertView alloc]initWithTitle:@"Erro!" message:@"Tuvimos un Error intente mas tarde" delegate:self cancelButtonTitle:@"Cancelar" otherButtonTitles:@"OK", nil];
[cError show];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"loginSuccess"]) {
[segue destinationViewController];
}
}
你应该检查 [NSNULL null]。 您在 Json 请求中收到一个或多个 NSNUll 值。
检查这可能是你需要的 - [NSNull isEqualToString:]
这些行将帮助您更多- NSMutableDictionary *dicAfterRemovingNull = [NSMutableDictionary dictionaryWithDictionary: yourDictionary]; // 如果字典和数组用 MutableArray 改变这一行
for(NSString *key in [dicAfterRemovingNull allKeys])
{
const id object = [dicAfterRemovingNull objectForKey:key];
if(object == [NSNull null])
{
[dicAfterRemovingNull setValue:@"whatever you want" forKey:key];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.