gpt4 book ai didi

ios - UIButton touchUpInside 与 UITableViewCell 滑动事件冲突

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:23:18 24 4
gpt4 key购买 nike

我在 UITableViewCell 中显示滑动按钮如下:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}

- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *cancelAction;
UITableViewRowAction *editAction;
UITableViewRowAction *messageAction;
cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[tableActivities setEditing:NO];
}];
cancelAction.backgroundColor = [UIColor blueColor];

editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[tableActivities setEditing:NO];
}];
editAction.backgroundColor = [UIColor greenColor];

messageAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Message" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[tableActivities deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];

return @[messageAction, cancelAction, editAction];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

}

在单元格的 contentView 中,我放置了一个 UIButton,它有一个 UIControlEventTouchUpInside controlEvent
当我通过触摸按钮区域滑动单元格时,滑动和 UIButton 事件都会被触发。
我该如何控制它?

最佳答案

您可以通过查看isEditing 来解决您的问题。 UITableView的属性(property)在你的button action像这样

- (void)btnTap:(UIButton*) sender {
if (!self.tableActivities.isEditing) {
//Perform Action
}
}

关于ios - UIButton touchUpInside 与 UITableViewCell 滑动事件冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38367041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com