开发者

How to use different cell in one table view?

开发者 https://www.devze.com 2023-03-29 03:59 出处:网络
How to use 3 different cells on one uitableview? I have 3 buttons now When 开发者_StackOverflow社区i press any button then cell of table view should be changed. Please helpIn the button\'s action meth

How to use 3 different cells on one uitableview? I have 3 buttons now When 开发者_StackOverflow社区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];

}

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;

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消