【发布时间】:2017-10-21 13:07:53
【问题描述】:
我有表格视图。当我滚动我的表格视图时,表格单元格中的文本标签正在混合。如何解决?
我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell3";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
UILabel *label = (UILabel *)[self.view viewWithTag:1];
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
label.text = [_array objectAtIndex:indexPath.row];
break;
case 1:
label.text = [_array objectAtIndex:indexPath.row];
break;
case 2:
label.text = [_array objectAtIndex:indexPath.row];
break;
}}
【问题讨论】:
-
缺少信息:我猜你有超过 3 个单元格,如果
if (indexPath.section != 0 && indexPath.row >2) {label.text = nil;}应该这样做? -
@Larme 我有超过 3 个单元格和超过 1 个部分
-
创建一个标签并将其添加到单元格的 contentView 将解决您的问题。
-
@Amit 我在情节提要中创建标签
-
如果您在情节提要的单元格中有标签,那么您为什么要分配它,为什么不将标签称为 cell.myLbl
标签: ios