我写了一个代码,给我的 TableView 中的每个单元格一个从 8 开始的数字,当它达到 12 时,我在应用程序小时内调用它的计数器
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
while (hour < 15)
{
if (hour == 12) {
hour=1;
} else {
NSString *str = [NSString stringWithFormat:@"%d",hour];
cell.textLabel.text = [courses objectAtIndex:indexPath.row];
cell.detailTextLabel.text = str;
NSLog(@"%@",str);
hour++;
return cell;
}
}
return cell;}
当我用模拟器运行应用程序时效果很好,但是当我滚动它时,它会不断更改第一个和第二个单元格中的数字,我希望即使滚动表格也不会改变数字。
我该怎么做?提前致谢。