Reputation: 185
Is there a way to remove UTableCell?
Basically I have two UIButtons
and two Custom UITableCell
and depending on what button is pressed I want to display the Custom UITableCell
Once the UIViewController
is loaded, it displays one of the Custom UITableCell
.
What I want to do is when the second UIButton
is pressed to remove the first UITableCell
and display the other one.
Upvotes: 0
Views: 342
Reputation: 3401
if (cell == nil) {
//If button 1 was clicked
static NSString *MyIdentifier = @"TableIdentifier1";
[[NSBundle mainBundle] loadNibNamed:@"TableViewCell1" owner:self options:nil];
cell = tableViewTblCell1; //tableViewCell1 is the object of TableViewCell1
self.tableViewTblCell1= nil;
//Else If button 2 was clicked
static NSString *MyIdentifier = @"TableIdentifier2";
[[NSBundle mainBundle] loadNibNamed:@"TableViewCell2" owner:self options:nil];
cell = tableViewTblCell2; //tableViewCell2 is the object of TableViewCell2
self.tableViewTblCell2= nil;
}
*and do whatever you want to do with cell *
Upvotes: 1
Reputation: 118651
You can just update your data source, then call -reloadData
on the table view. If you want to use animation, you can also use -insertRowsAtIndexPaths:withRowAnimation:
and -deleteRowsAtIndexPaths:withRowAnimation:
.
Upvotes: 1
Reputation: 19418
you need to create your custom cell based on your button click for that you need to remember which button is clicked.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([aVarible isEqualToString:@"firstButton"])
{
//create your first custom cell
}
else if ([aVarible isEqualToString:@"secondButton"])
{
//create your second custom cell
}
}
in your button click event
- (IBAction) firstBtnClick
{
aVarible = @"firstButton"
[yourTable reloadData]
}
- (IBAction) secondBtnClick
{
aVarible = @"secondButton"
[yourTable reloadData]
}
hope it gives to idea.
Upvotes: 1