Joh*_*Doe 0 objective-c uitableview ios
虽然我意识到这是开发人员中的一个流行问题,但Stack Overflow上有许多类似的问题,但没有人能够帮我解决这个问题.UITableView存在一个奇怪的问题,即单个单元格混合在一起,或者看似混乱.我相信我正在重复使用细胞,只需要第二眼.这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.friendFullName.text = [users objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我在一个单独的UITableCell中使用动态的自定义单元格.
你的细胞正在重复使用.将标签设置为willDisplayCell而不是cellForRowAtIndexPath.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
SimpleTableCell *simpleTableCell = (SimpleTableCell *)cell;
simpleTableCell.friendFullName.text = [users objectAtIndex:indexPath.row];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
754 次 |
| 最近记录: |