[self.tableView registerNib:[UINib nibWithNibName:@"NewTaskCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:NewTaskCellId];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NewTaskCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NewTaskCellId forIndexPath:indexPath];
if (!cell) {
cell = [[NewTaskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NewTaskCellId];
}
if (self.taskList.count > indexPath.row) {
FindDisOrderInfoEntity *entity = [self.taskList objectAtIndex:indexPath.row];
[cell setCellContentWith:entity];
}
return cell;
}
迷茫2017-04-18 09:59:24
Remove if (self.taskList.count > indexPath.row)
Cell is assigned normally
When the cell is added, refresh the table or refresh the new row
巴扎黑2017-04-18 09:59:24
You should first look at the number of your cells. Secondly, the concept of cells is containers. Reuse is just reusing containers. The decision lies with the data source
阿神2017-04-18 09:59:24
You have already registered using the registerNib method. There is no need to determine whether the cell is empty in the proxy method
高洛峰2017-04-18 09:59:24
Write this in the (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath proxy method:
NewTaskCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NewTaskCellId forIndexPath:indexPath];
FindDisOrderInfoEntity *entity = [self.taskList objectAtIndex:indexPath.row]; [cell setCellContentWith:entity];
return cell;
PHP中文网2017-04-18 09:59:24
Cell reuse, the previous state is reused, such as the UIButton
和 UILabel
如果在重用之前UIButton
是高亮状态 UILabel
上的text=@"label"
那么重用之后,UIButton
还是高亮状态,UILabel
的text
还是label
,cell
重用的时候会调用cellForRow
方法。所以一般会在cellForRow
里面重新赋值和改变状态。所以在cell里面有个默认的规则 就是如果有if 那一定要有else
on the cell, otherwise the cell will become messy.
PHP中文网2017-04-18 09:59:24
After registration, you don’t have to judge whether the cell is empty, but there is nothing wrong with it. Why does your count need to be judged? I don’t understand. Maybe your array is not a data source? But it probably isn't your problem. If your "duplication of content" means that the controls on the cell are added repeatedly, then it should be [cell setCellContentWith:entity]; There may be something wrong with the method in this. It may be that you are Create the control here and add it. Reuse only refreshes the data, that is, only the assignment process does not create the control
迷茫2017-04-18 09:59:24
If the tableview doesn’t display much, it won’t be repeated if you don’t let it be reused. Also, after calling the registerNib method, the memory will always be in CELL