我的应用程序有一个来自服务器的列表,每次滚动时我都会发送新数据请求并重新加载它。我接受了 10 个细胞。这工作就好了。
但问题是,如果我更改例如 1 个单元格中的值,它会在单元格 8、15 等中更改。
数据是类,我从服务器获取信息以显示在单元格中。getDataAt 是我的单元格类中的方法,它将值放入单元格中。
在 numberOfRowsInSection 中,我正在检查列表是否完整,表格视图显示附加单元格以加载更多行,如果列表不完整,则意味着没有更多行可显示并且此单元格将不会显示。
代码 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row < [self.list size])
{
static NSString *cellIdentifier = @"CellIdentifier";
self.cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
Data* data = [self.list getDataAt:indexPath.row];
NSLog(@"%@", indexPath);
cell.delegate = self;
[cell setCell:data];
return _cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.list size] + (self.list.complete ? 0 : 1);
}
到目前为止我发现的是,当我向上和向下滚动时,indexPath 会变得混乱,当他再添加 10 个单元格时,它需要 indexPath.row 以前的单元格。