【发布时间】:2012-07-27 00:08:03
【问题描述】:
我检查了其他几个问题,但仍然无法弄清楚为什么会发生这种情况。我所知道的是在使用来自this 问题的描述代码之后,单元格的值是null。我已经正确设置了table 的delegate 和datasource,但我看不出哪里出了问题。
如果我将以下方法的返回值设置为 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,并将这个项目与其他项目进行了比较,看看我是否遗漏了什么,但我看不出任何真正的差异。
【问题讨论】:
标签: ios datasource tableview