我检查了其他一些问题,但仍然无法弄清楚为什么会发生这种情况。我所知道的是,在使用此问题中的描述代码后,单元格的值为null
. 我已经正确设置了delegate
和datasource
,但table
我看不出哪里出了问题。
如果我将以下方法的返回值设置为 0,则不会发生错误,因为该cellForRowAtIndexPath
方法并没有真正发生。因此,如果我将其设置为 1(应该如此),它将引发错误。我已经合成NSArray
并检查了它的填充(尽管我猜这不重要)并且基本上意味着发生的事情是我按下button
搜索然后将结果放在table
. 所以在此之前tableview
是空的。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
这是cellForRowAtIndexPath
方法本身。我也尝试过使用基本模板方法,但仍然会引发相同的错误。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
NSDictionary *aResult = [results objectAtIndex:[indexPath row]];
NSLog(@"RESULTS IN TABLE %i", [results count ]);
id key = [results objectAtIndex:[indexPath row]];
resultTitle.text=@"Hello";
NSURL *url = [NSURL URLWithString:[aResult objectForKey:@"url"]];
NSData *data = [NSData dataWithContentsOfURL:url];
cell.imageView.image = [UIImage imageWithData:data];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[theTableView reloadData];
return cell;
}
我不知道出了什么问题。我以前使用tableviews
过这个项目,并将这个项目与其他项目进行了比较,看看我是否遗漏了一些东西,但我看不出任何真正的差异。