【发布时间】:2012-06-01 07:41:05
【问题描述】:
我已经解决这个问题 2 天了。我参考了一些 SO 问题,例如 Link 1 。问题是我有 2 行和数组计数部分的组表。当我滚动表格时,意味着第 4 部分重复了第 1 部分的值,但它在第 3 部分中效果很好。这两行都取第一节行的值
我的代码是:
static NSString *CellIdentifier = @"Cell";
cell = (CopyableTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CopyableTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:CellIdentifier] autorelease];
}
cell.delegate = self;
/*UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
//cell.detailTextLabel.lineBreakMode=UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines=2;
cell.detailTextLabel.font=[UIFont systemFontOfSize:14];*/
// Configure the cell...
DLog(@"");
//cell setBackgroundColor:[UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:0.8]]
cell.textLabel.textColor = [UIColor blackColor];//[UIColor colorWithRed:0.22 green:0.33 blue:0.53 alpha:0.8];
cell.detailTextLabel.textColor = [UIColor blackColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
l=indexPath.section;
switch (indexPath.row) {
case 0:
cell.textLabel.text =@"Quantity";
if (indexPath.section ==k) {
cell.detailTextLabel.text = self.qtyValue;
[cell.detailTextLabel setTag:indexPath.section];
}
break;
case 1:
cell.textLabel.text = @"Unit";
if (indexPath.section ==j) {
cell.detailTextLabel.text = [self.unitValue valueForKey:@"val"];
[cell.detailTextLabel setTag:indexPath.section];
}
break;
default:
break;
}
任何人都可以为此提供解决方案
【问题讨论】:
-
我在 j 和 k 右侧有 count 个节,代表节中的相应单元格。即第一个和第二个单元格
-
但是您将 j & k 与 section 而非 row 进行比较。如果 j & k 表示单元格,那么您应该将其与 indexPath.row 进行比较,而不是与 indexPath.section 进行比较。
-
实际上 j&k 代表单元格,但我们在单元格中有多个具有不同值的部分。
标签: iphone ios uitableview sections