我一直在处理这个问题2天。我已经提到了一些像Link 1 这样的问题。问题是什么我有2行和数组计数部分的组表。当我滚动表格意味着第4部分重复第1部分的值,但它可以很好地工作到3部分。这两行都采用第1节行的值
我的代码是:
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;
}
可以为此提供解决方案
答案 0 :(得分:0)
如果你的要求是,你有多个部分,每个部分有2行/单元格,那么我宁愿建议你在cellforRowAtIndexPath中这样编码:
switch(indexPath.row)
{
case 0:
{
switch(indexPath.section)
{
case 0:
{
//Statement needs to execute for cell0 in section 0.
}
break;
case 1:
{
//Statement needs to execute for cell0 in section 1.
}
break;
case 2:
{
//Statement needs to execute for cell0 in section 2.
}
break;
case 3:
{
//Statement needs to execute for cell0 in section 3.
}
break;
}
}
break;
case 1:
{
switch(indexPath.section)
{
case 0:
{
//Statement needs to execute for cell1 in section 0.
}
break;
case 1:
{
//Statement needs to execute for cell1 in section 1.
}
break;
case 2:
{
//Statement needs to execute for cell1 in section 2.
}
break;
case 3:
{
//Statement needs to execute for cell1 in section 3.
}
break;
}
}
break;
default:
break;
}