Uitableview 调度时未捕获的异常\u async
我得到了一个未捕获的错误,我相信它在一个块内(iOS 7)。但是,由于NSException只显示在调试日志上,因此我很难知道是什么导致了它 这是我的密码:Uitableview 调度时未捕获的异常\u async,uitableview,ios7,objective-c-blocks,grand-central-dispatch,Uitableview,Ios7,Objective C Blocks,Grand Central Dispatch,我得到了一个未捕获的错误,我相信它在一个块内(iOS 7)。但是,由于NSException只显示在调试日志上,因此我很难知道是什么导致了它 这是我的密码: -(void)insertIntoArray:(NSArray *)array { @try { if([array count] > 0){ NSArray *anArray = [array copy]; dispatch_queue_t q = dispatch_queue_create(
-(void)insertIntoArray:(NSArray *)array
{
@try {
if([array count] > 0){
NSArray *anArray = [array copy];
dispatch_queue_t q = dispatch_queue_create("getCustomerList", NULL);
dispatch_async(q, ^(void){
for (NSDictionary *dict in anArray){
Customer *customer = [[Customer alloc]init];
NSInteger i = [[dict objectForKey:@"CustomerID"] integerValue];
customer.ID = i;
customer.AppointmentID = [dict objectForKey:@"AppointmentID"];
customer.UID = [dict objectForKey:@"UID"];
customer.AccountNumber = [dict objectForKey:@"AccountNumber"];
customer.Birthdate = [dict objectForKey:@"Birthdate"];
customer.Gender = [dict objectForKey:@"Gender"];
customer.FirstName = [dict objectForKey:@"Firstname"];
customer.MiddleName = [dict objectForKey:@"MiddleName"];
customer.LastName = [dict objectForKey:@"LastName"];
customer.Address = [dict objectForKey:@"address1"];
customer.PhoneNumber = [dict objectForKey:@"PhoneNumber"];
customer.PictureName = [dict objectForKey:@"PictureName"];
customer.LastVisit= [dict objectForKey:@"LastVisit"];
customer.AccountOpened = [dict objectForKey:@"AccountOpened"];
customer.PhoneNumber2 = [dict objectForKey:@"HPNum"];
customer.DisplayName = [dict objectForKey:@"DisplayName"];
customer.ProfileImage = [dict objectForKey:@"ProfileImage"];
customer.EmailAddress = [dict objectForKey:@"EmailAddress"];
customer.Allergy = [dict objectForKey:@"Allergy"];
char index = [[dict objectForKey:@"DisplayName"] characterAtIndex:0];
NSString *uniChar = [NSString stringWithFormat:@"%c",index];
if(![self.arrayOfIndices containsObject:uniChar]){
[self.arrayOfIndices addObject:uniChar];
}
[self.arrayOfCustomer addObject:customer];
}
self.segmentedControl.userInteractionEnabled = YES;
[self.indicator stopAnimating];
[self.indicator removeFromSuperview];
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
self.isRefreshing = NO;
[self.tableView setUserInteractionEnabled:YES];
self.tableView.scrollEnabled = YES;
self.navigationItem.rightBarButtonItem.enabled = true;
[self.refreshControl endRefreshing];
[self.tableView setContentOffset:CGPointMake(0.0, 0.0) animated:NO];
});
}
else {
[self.indicator stopAnimating];
[self.indicator removeFromSuperview];
self.isRefreshing = NO;
[self.tableView setUserInteractionEnabled:YES];
self.tableView.scrollEnabled = YES;
self.navigationItem.rightBarButtonItem.enabled = true;
[self.refreshControl endRefreshing];
}
}
@catch (NSException *exception) {
NSLog(@"Error %@",exception);
[self alertStatus:[NSString stringWithFormat:@"An unexpected error has occured. Exception %@", exception.reason] :@"Error!"];
}
self.navigationItem.rightBarButtonItem.enabled = true;
}
下面是NSException在日志上的样子
我的问题是,有没有办法从一个块中获取异常原因或描述?如果没有,我的代码中是否有任何错误导致了错误
如果有人能帮忙,我会很高兴的。干杯 好的,我读了一些关于GCD的书,我提出了这个解决方案。我不知道这是不是正确的方法。但它现在起作用了
-(void)insertIntoCustomerArray:(NSArray *)array
{
@try {
[self.arrayOfCustomers removeAllObjects];
if([array count] > 0) {
__block LoginViewController *blockSelf = self;
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
__block NSArray *blockArray = [array copy];
dispatch_sync(concurrentQueue, ^{
for (NSDictionary *dict in blockArray){
Customer *customer = [[Customer alloc]init];
NSInteger i = [[dict objectForKey:@"CustomerID"] integerValue];
customer.ID = i;
customer.AppointmentID = [dict objectForKey:@"AppointmentID"];
customer.UID = [dict objectForKey:@"UID"];
customer.AccountNumber = [dict objectForKey:@"AccountNumber"];
customer.Birthdate = [dict objectForKey:@"Birthdate"];
customer.Gender = [dict objectForKey:@"Gender"];
customer.FirstName = [dict objectForKey:@"Firstname"];
customer.MiddleName = [dict objectForKey:@"MiddleName"];
customer.LastName = [dict objectForKey:@"LastName"];
customer.Address = [dict objectForKey:@"address1"];
customer.PhoneNumber = [dict objectForKey:@"PhoneNumber"];
customer.PictureName = [dict objectForKey:@"PictureName"];
customer.LastVisit= [dict objectForKey:@"LastVisit"];
customer.AccountOpened = [dict objectForKey:@"AccountOpened"];
customer.PhoneNumber2 = [dict objectForKey:@"HPNum"];
customer.DisplayName = [dict objectForKey:@"DisplayName"];
customer.ProfileImage = [dict objectForKey:@"ProfileImage"];
customer.EmailAddress = [dict objectForKey:@"EmailAddress"];
customer.Allergy = [dict objectForKey:@"Allergy"];
char index = [[dict objectForKey:@"DisplayName"] characterAtIndex:0];
NSString *uniChar = [NSString stringWithFormat:@"%c",index];
if(![blockSelf.arrayOfIndices containsObject:uniChar]){
[blockSelf.arrayOfIndices addObject:uniChar];
}
[blockSelf.arrayOfCustomers addObject:customer];
}
});
dispatch_async(dispatch_get_main_queue(), ^{
[self removeIndicatorView];
});
});
}
else {
}
}
@catch (NSException *exception) {
NSLog(@"Error %@", exception.reason);
[self alertStatus:[NSString stringWithFormat:@"Error while fetching the customer list. Exception %@", exception] :@"Error!"];
}
}显示堆栈跟踪。我建议您为所有Objective-C异常创建一个断点。