如何检测用户何时刷过可编辑的UITableViewCell?

时间:2021-10-31 21:07:16

I have an editable UITableView. By default the user can swipe and the Delete button will show up. I would like to hide some elements on my UITableView cell when this occurs. How can I do this?

我有一个可编辑的UITableView。默认情况下,用户可以滑动,并显示“删除”按钮。当发生这种情况时,我想在我的UITableView单元格中隐藏一些元素。我怎样才能做到这一点?

5 个解决方案

#1


2  

Try overriding the willTransitionToState method in your custom UITableViewCell. In particular you would be interested in the UITableViewCellStateShowingDeleteConfirmationMask state.

尝试覆盖自定义UITableViewCell中的willTransitionToState方法。特别是你会对UITableViewCellStateShowingDeleteConfirmationMask状态感兴趣。

#2


4  

Oh c'mon:

tableView:willBeginEditingRowAtIndexPath:

...

Discussion

This method is called when the user swipes horizontally across a row; as a consequence, the table view sets its editing property to YES (thereby entering editing mode) and displays a Delete button in the row identified by indexPath. In this "swipe to delete" mode the table view does not display any insertion, deletion, and reordering controls. This method gives the delegate an opportunity to adjust the application's user interface to editing mode. When the table exits editing mode (for example, the user taps the Delete button), the table view calls tableView:didEndEditingRowAtIndexPath:.

当用户在一行中水平滑动时调用此方法;因此,表视图将其编辑属性设置为YES(从而进入编辑模式),并在indexPath标识的行中显示“删除”按钮。在“滑动删除”模式下,表视图不显示任何插入,删除和重新排序控件。此方法使代理人有机会将应用程序的用户界面调整为编辑模式。当表退出编辑模式时(例如,用户点击“删除”按钮),表视图调用tableView:didEndEditingRowAtIndexPath:。

Reference

And then throw some [[cell viewWithTag:<#View's tag number#>] setHidden:YES] for your own views.

然后为您自己的视图抛出一些[[cell viewWithTag:<#View的标签号#>] setHidden:YES]。

#3


1  

Couldn't you modify the pertinent elements of the – tableView:willBeginEditingRowAtIndexPath: is called?

难道你不能修改 - tableView的相关元素:willBeginEditingRowAtIndexPath:被调用吗?

#4


0  

As soon as the user wants to editing something in his tableView, this method gets called

一旦用户想要在他的tableView中编辑某些内容,就会调用此方法

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

if(editing){
     // Entered Edit mode

     // Show the new tableView and reload it.
} 

else {
    // End of edit mode

    // Bring back the tableview and again reload it. 
}


[super setEditing:editing animated:animated];

}

#5


0  

Update your UI in tableView:willBeginEditingRowAtIndexPath: and Restore in tableView:didEndEditingRowAtIndexPath:.

更新tableView中的UI:willBeginEditingRowAtIndexPath:并在tableView中执行:didEndEditingRowAtIndexPath:。

#1


2  

Try overriding the willTransitionToState method in your custom UITableViewCell. In particular you would be interested in the UITableViewCellStateShowingDeleteConfirmationMask state.

尝试覆盖自定义UITableViewCell中的willTransitionToState方法。特别是你会对UITableViewCellStateShowingDeleteConfirmationMask状态感兴趣。

#2


4  

Oh c'mon:

tableView:willBeginEditingRowAtIndexPath:

...

Discussion

This method is called when the user swipes horizontally across a row; as a consequence, the table view sets its editing property to YES (thereby entering editing mode) and displays a Delete button in the row identified by indexPath. In this "swipe to delete" mode the table view does not display any insertion, deletion, and reordering controls. This method gives the delegate an opportunity to adjust the application's user interface to editing mode. When the table exits editing mode (for example, the user taps the Delete button), the table view calls tableView:didEndEditingRowAtIndexPath:.

当用户在一行中水平滑动时调用此方法;因此,表视图将其编辑属性设置为YES(从而进入编辑模式),并在indexPath标识的行中显示“删除”按钮。在“滑动删除”模式下,表视图不显示任何插入,删除和重新排序控件。此方法使代理人有机会将应用程序的用户界面调整为编辑模式。当表退出编辑模式时(例如,用户点击“删除”按钮),表视图调用tableView:didEndEditingRowAtIndexPath:。

Reference

And then throw some [[cell viewWithTag:<#View's tag number#>] setHidden:YES] for your own views.

然后为您自己的视图抛出一些[[cell viewWithTag:<#View的标签号#>] setHidden:YES]。

#3


1  

Couldn't you modify the pertinent elements of the – tableView:willBeginEditingRowAtIndexPath: is called?

难道你不能修改 - tableView的相关元素:willBeginEditingRowAtIndexPath:被调用吗?

#4


0  

As soon as the user wants to editing something in his tableView, this method gets called

一旦用户想要在他的tableView中编辑某些内容,就会调用此方法

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

if(editing){
     // Entered Edit mode

     // Show the new tableView and reload it.
} 

else {
    // End of edit mode

    // Bring back the tableview and again reload it. 
}


[super setEditing:editing animated:animated];

}

#5


0  

Update your UI in tableView:willBeginEditingRowAtIndexPath: and Restore in tableView:didEndEditingRowAtIndexPath:.

更新tableView中的UI:willBeginEditingRowAtIndexPath:并在tableView中执行:didEndEditingRowAtIndexPath:。