我正在使用下面的代码 - UITableViewDataSource 方法如下:
numberOfRowsInSection
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
}
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = dataArray[indexPath.row];
return cell;
}
最佳答案
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
但在 iOS 5 中,创建 UITableViewCell 的实例我们通常使用这种方法:-
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
在 iOS 5 中,不需要您在 iOS 6 中使用的额外参数。只需删除它,它就会起作用 (forIndexPath:)。
关于ios - 为什么 tableview 在 iOS 6+ 模拟器上工作正常,但在 iOS 5 模拟器上它崩溃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21732982/