我需要另一双眼睛。
奇怪的是,我似乎无法访问自定义 NSError 上的属性。我不断收到 EXC_BAD_ACCESS 错误。这是我的代码:
if (response.isUnauthorized)
{
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:response.bodyAsString forKey:@"Error Message"];
NSError *unAuthorizedError = [NSError errorWithDomain:@"MyApp" code: [response statusCode] userInfo:userInfo];
[delegate dataControllerLoadFailed:unAuthorizedError];
[ErrorHandler logError:unAuthorizedError fromClassName:NSStringFromClass([self class]) fromSelectorName:NSStringFromSelector(_cmd) ];
}
这调用:
-(void)dataControllerLoadFailed:(NSError *)error
{
NSString *message = [NSString stringWithFormat:@"Encountered an error: %@ - ", error.code];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[activityIndicator stopAnimating];
}
在 dataControllerLoadFailed 中创建消息 NSString 时出现错误访问错误,无论是使用 error.code 还是错误对象上的任何其他成员...
所以这失败了:
NSString *message = [NSString stringWithFormat:@"Encountered an error: %@ - ", error.code];
但奇怪的是,这成功了:
NSString *message = [NSString stringWithFormat:@"Encountered an error: %@ - ", error];
感谢任何给这个时间的人!