2011-08-09 59 views
0


有没有办法删除UTableCell?
基本上我有两个UIButtons和两个自定义UITableCell
并根据按下哪个按钮我想一旦UIViewController被加载,显示自定义UITableCell
,它会显示自定义UITableCell之一。
我想要做的是当第二个UIButton被按下以删除第一个UITableCell并显示另一个。删除UITableViewCell定制

回答

1
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; 
} 

* ,做任何你想要的细胞做*

+0

感谢这有助于。 – Mush

+0

@Mush任何时候:) –

1

您需要基于点击按钮创建您的自定义单元格,以便您需要记住哪个按钮被点击。

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

在按钮单击事件

- (IBAction) firstBtnClick 
{ 
    aVarible = @"firstButton" 
    [yourTable reloadData] 
} 

- (IBAction) secondBtnClick 
{ 
    aVarible = @"secondButton" 
    [yourTable reloadData] 
} 

希望它给的想法。

1

您可以更新您的数据源,然后在表视图上调用-reloadData。如果你想使用动画,你也可以使用-insertRowsAtIndexPaths:withRowAnimation:-deleteRowsAtIndexPaths:withRowAnimation: