[英]UITableView deleting rows, commitEditingStyle method not firing?
[英]UITableView commitEditingStyle only on particular cases
僅在某些情況下才可以通過添加commitEditingStyle
方法來使UITableView
可編輯嗎?
我有一個controller.m / .h文件,它正在為3種不同的故事板viewcontrollers做東西。 我只希望3個中的2個能夠commitEditingStyle。 我可以使用self.restorationIdentifier
區分它們。
您可以檢查tableview標記。
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableview.tag==1 || tableview.tag==2)
return UITableViewCellEditingStyleDelete;
return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
//here your code
}
}
public override UITableViewCellEditingStyle EditingStyleForRow(UITableView tableView, NSIndexPath indexPath)
{
//here we show and hide the delete for particular row
if (indexPath.Row ==1)
{
return UITableViewCellEditingStyle.Delete;
}
else {
return UITableViewCellEditingStyle.None;
}
}
public override void CommitEditingStyle(UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
{
if (editingStyle == UITableViewCellEditingStyle.Delete)
{
//here we handle delete button action of the tableview
}
}
好吧,似乎我只需要將其子類化,然后在子類上添加commitEditingStyle
。 然后將情節提要中的類更改為子類,僅此而已。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.