UITableview中的最后一行复制到其他行

时间:2012-01-24 14:43:15

标签: iphone objective-c uitableview

我有一个UITableView,它被分成几个部分,每个部分都有很多行,所有的行都被禁用,因此它们只显示信息,除最后一行外,它们不允许用户交互。但是当用户滚动表格时,最后一行将被复制到表格中的某些其他行。这是我的代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.userInteractionEnabled = NO;
    cell.accessoryType = UITableViewCellAccessoryNone;
    UIFont *textLabelFont = [ UIFont fontWithName: @"Arial" size: 13.0 ];
    UIFont *detailLabelFont = [UIFont fontWithName:@"Arial" size:13.0];
    cell.textLabel.font  = textLabelFont;
    cell.detailTextLabel.font = detailLabelFont;

    // Configure the cell.
    [populatePolicyCells ProcessPolicyCell:cell IndexPath:indexPath];

    if (indexPath.section == 3){
            tableView.allowsSelection = YES;
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier] autorelease];
            cell.userInteractionEnabled = YES;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    cell.textLabel.text = @"Manage Policy";  
    }
    return cell;
}

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

为“特殊单元格”设置不同的CellIdentifier

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell* cell = nil;
    if (indexPath.section == 3)
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"SpecialCell"];
        if(cell == nil)
        {
            tableView.allowsSelection = YES;
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:"SpecialCell"] autorelease];
            cell.userInteractionEnabled = YES;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        }
        cell.textLabel.text = @"Manage Policy";
    }
    else
    {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil)
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.userInteractionEnabled = NO;
            cell.accessoryType = UITableViewCellAccessoryNone;
            UIFont *textLabelFont = [ UIFont fontWithName: @"Arial" size: 13.0 ];
            UIFont *detailLabelFont = [UIFont fontWithName:@"Arial" size:13.0];
            cell.textLabel.font  = textLabelFont;
            cell.detailTextLabel.font = detailLabelFont;
        }
        // Configure the cell.
        [populatePolicyCells ProcessPolicyCell:cell IndexPath:indexPath];
    }
    return cell;
}

答案 1 :(得分:0)

每次重复使用tableview时都会更改dequeueCellWithIdentifier