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;
}
精彩评论