0
我有此代码,用于检查用户是否已验证完成在应用程序上注册:终止应用程序,由于未捕获的异常'NSRangeException' - [__ NSArrayI objectAtIndex:]:索引1超越界限[0..0]'
-(void)handleVerify:(UITapGestureRecognizer *)recognizer{
__block BOOL foundError = false;
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
UIView *transparentView = [[UIView alloc] init];
transparentView.frame = self.view.frame; //Provide frame of right side view.
transparentView.alpha = 0.5; //To provide transparent look and feel.
transparentView.backgroundColor = [UIColor blackColor];
[self.view addSubview:transparentView];
//activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.center = CGPointMake(transparentView.frame.size.width/2, transparentView.frame.size.height/2);
[transparentView addSubview:activityIndicator];
[activityIndicator startAnimating];
if(textfieldVerifyEmail.text.length > 0){
labelErrorVerfiyEmail.hidden = YES;
}else{
foundError = true;
labelErrorVerfiyEmail.hidden = NO;
}
if(textfieldVerifyNumber.text.length > 0){
labelErrorVerifyNumber.hidden = YES;
}else{
foundError = true;
labelErrorVerifyNumber.hidden = NO;
}
if(!foundError){
dispatch_queue_t concurrentQueue2 = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// 3) Load picker in background
dispatch_async(concurrentQueue2, ^{
NSString *myRequestString = [NSString stringWithFormat:@"email=%@&ver=%@", textfieldVerifyEmail.text,textfieldVerifyNumber.text];
NSString *response = [self setupPhpCall:myRequestString :@"checkUserVerification.php"];
dispatch_async(dispatch_get_main_queue(), ^{
if(response.length > 0){
NSArray *items = [response componentsSeparatedByString:@"|~|"];
NSString *ver =[items objectAtIndex:0];
NSString *idUser =[items objectAtIndex:1];
if([ver isEqualToString:@"verified"]){
textfieldVerifyNumber.text = @"";
textfieldVerifyEmail.text = @"";
[activityIndicator stopAnimating];
[transparentView removeFromSuperview];
[activityIndicator removeFromSuperview];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"REGISTERED" message:@"You are now Registered" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil, nil];
[alert show];
userID = [idUser intValue];
[viewCreds removeFromSuperview];
[viewCredsRegister removeFromSuperview];
[viewCredsSignin removeFromSuperview];
[viewCredsVerify removeFromSuperview];
[self setupHeader];
[self setupNavigation];
[self setupFooter];
[self setupFooterNavigation];
[self switchView:7];
[self switchView:1];
}else{
[activityIndicator stopAnimating];
[transparentView removeFromSuperview];
[activityIndicator removeFromSuperview];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"VERIFICATION INVALID" message:@"Our records show that the Verification Number is incorrect, please try again or contact [email protected]" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil, nil];
[alert show];
}
}else{
[activityIndicator stopAnimating];
[transparentView removeFromSuperview];
[activityIndicator removeFromSuperview];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"SERVER ERROR" message:@"Server not Responding, please try back later..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil, nil];
[alert show];
}
});
});
}else{
[activityIndicator stopAnimating];
[transparentView removeFromSuperview];
[activityIndicator removeFromSuperview];
}
}
但我只要我点击确认收到此错误按钮:
[1649:65950] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x00e2c746 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x006a2a97 objc_exception_throw + 44
2 CoreFoundation 0x00d0dcb2 -[__NSArrayI objectAtIndex:] + 210
3 InstantForum 0x000944ab __31-[ViewController handleVerify:]_block_invoke_2 + 203
4 libdispatch.dylib 0x052fc5ea _dispatch_call_block_and_release + 15
5 libdispatch.dylib 0x0531ebef _dispatch_client_callout + 14
6 libdispatch.dylib 0x053046bb _dispatch_main_queue_callback_4CF + 993
7 CoreFoundation 0x00d858ee __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
8 CoreFoundation 0x00d435f0 __CFRunLoopRun + 2256
9 CoreFoundation 0x00d42a5b CFRunLoopRunSpecific + 443
10 CoreFoundation 0x00d4288b CFRunLoopRunInMode + 123
11 GraphicsServices 0x047682c9 GSEventRunModal + 192
12 GraphicsServices 0x04768106 GSEventRun + 104
13 UIKit 0x013ff0b6 UIApplicationMain + 1526
14 InstantForum 0x00112e9a main + 138
15 libdyld.dylib 0x05349ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(Recorded Frame)
在此行的代码中出现的错误:
dispatch_async(dispatch_get_main_queue(), ^{
你的显示器有多高? – nhgrif
32英寸,为什么。 – redoc01
因为你的代码中有太多空白,所以你无法读取它。 – justinpawela