ios - 为什么 tableview 在 iOS 6+ 模拟器上工作正常,但在 iOS 5 模拟器上它崩溃了

标签 ios objective-c uitableview

我正在使用下面的代码 - 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/

相关文章:

ios - 在 UITableViewCell 中加载 React Native View (RCTRootView)

android - 在 iOS 和 Android 上 react native 模态模糊/活力?

ios - 如何使用完成处理程序方法运行 for 循环?

ios - TableView 的 Swift 问题

iphone - 自定义 UICollectionViewCell 出错

swift - 表格 ScrollView 下的文本 swift

iOS客户端: I can have user sign into Active Directory,但是如何访问MS Graph API?

objective-c - 如何从 Swift 调用 Objective-C 单例?

objective-c - NSTextField 自动完成方法

swift - Xcode Swift 在 tableView 中显示来自 CloudKit 的数据