【问题标题】:How to use different cell in one table view?如何在一个表格视图中使用不同的单元格?
【发布时间】:2011-10-29 17:55:09
【问题描述】:

如何在一个 uitableview 上使用 3 个不同的单元格?我现在有 3 个按钮当我按下任何按钮时,应该更改表格视图的单元格。请帮忙

【问题讨论】:

  • 3 个不同的单元格是什么意思?

标签: iphone uitableview cell


【解决方案1】:

在按钮的操作方法中,保存点击的按钮并重新加载要更改单元格的行。

-(void)button1Tapped:(id)sender
{

    self.buttonIndex = 1;
    NSArray* arr = [[NSArray alloc] initWithObjects:self.indexPathOfConcernedCell, nil];
    [self.tableView reloadRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationNone];
    [arr release];

}

然后,在cellForRowAtIndexPath: 中返回单元格一个,根据哪个按钮被按下-

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {

    if(indexPath == self.indexPathOfConcernedCell)
    {

    if(self.buttonIndex == 1)
             {
                  Cell1* cell = (Cell1*) [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier1"];

                  if(cell == nil)
                  {
                 cell = [[[Cell1 alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"CellIdentifier1"] autorelease];
                  } 
             }

        else if(self.buttonIndex == 2)
        {
            //do similar stuff
        }

        //do similar stuff for buttonIndex 3 here

        }
    }

    else
    {
        //your regular stuff
    }

    return cell;

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多