如何在一个表视图中使用不同的单元格? [英] How to use different cell in one table view?

查看:75
本文介绍了如何在一个表视图中使用不同的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to use 3 different cells on one uitableview? I have 3 buttons now When i press any button then cell of table view should be changed. Please help

推荐答案

在按钮的操作方法中,保存点击了哪个按钮的内容。重新加载要在其中更改单元格的行。

In the button's action method, save which button was tapped & reload the row in which you want to change the cell.

-(void)button1Tapped:(id)sender
{

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

}

然后,在 cellForRowAtIndexPath:返回单元格中按下按钮的基础-

Then, in cellForRowAtIndexPath: return the cell one the basis of which button was pressed-

 - (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;

    }

这篇关于如何在一个表视图中使用不同的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆