我有一个让我发疯的错误。我有一个NSArray
被叫的问题。该数组由 JSON 响应填充。我正在尝试使用它来填充表格视图。
在我的头文件中,我正在定义这样的问题
@interface OneViewController : UITableViewController <MBProgressHUDDelegate> {
NSArray *questions;
MBProgressHUD *HUD;
}
@property (nonatomic, strong) NSArray *questions;
在我的实现中,我像这样实例化它
@synthesize questions;
当视图加载时,我正在调用这个函数来 ping 我的 JSON 服务
- (void) pullQuestions {
NSMutableDictionary *viewParams = [NSMutableDictionary new];
[viewParams setValue:@"questions" forKey:@"view"];
[PythonView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) {
questions = responseObject;
NSLog(@"Qestions: %@", responseObject);
[self.tableView reloadData];
[HUD hide:YES];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//ALog(@"Failure: %@", [error localizedDescription]);
}];
}
当我得到响应时,我会追踪响应对象,它是一个格式正确的 JSON 响应。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"VideoFeedCell";
NSInteger count = [questions count];
NSLog(@"Count: %i", count);
for (int i = 0; i < count; i++) {
NSString* body = [questions objectAtIndex:i];
NSLog(@"Object: %@", body);
}
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"VideoFeedCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
}
因此,当我遍历此内容时,问题计数为 4,并且跟踪了数组中的第一个对象(为 null)。它第二次尝试执行 for 循环时,我得到EXC_BAD_ACCESS
. 几乎就像问题数组消失了一样。最奇怪的是我在另一个项目中使用了几乎完全相同的代码,它工作正常。我什至使用我在另一个项目中使用的相同 JSON 服务对其进行了测试(所以我知道它没有格式错误或其他什么),但我仍然收到此错误。我真的卡住了,我觉得它必须与保存有关JSON响应作为一个数组或它自己被释放的数组的一些奇怪的东西。