gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:08:33 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com