Ios UIButton touchUpInside与UITableViewCell滑动事件冲突
我正在Ios UIButton touchUpInside与UITableViewCell滑动事件冲突,ios,objective-c,uitableview,uibutton,Ios,Objective C,Uitableview,Uibutton,我正在UITableViewCell中显示滑动按钮,如下所示: - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtI
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 {
}
-(BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(nsindepath*)indepath
{
返回YES;
}
-(可为空的NSArray*)tableView:(UITableView*)tableView编辑操作ErrorWatIndeXPath:(NSIndexPath*)indexPath
{
UITableViewRowAction*取消操作;
UITableViewRowAction*编辑操作;
UITableViewRowAction*消息操作;
cancelAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@“Cancel”处理程序:^(UITableViewRowAction*action,NSIndexPath*indexPath){
[表格编辑:否];
}];
cancelAction.backgroundColor=[UIColor blueColor];
editAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal标题:@“编辑”处理程序:^(UITableViewRowAction*action,NSIndexPath*indexPath){
[表格编辑:否];
}];
editAction.backgroundColor=[UIColor greenColor];
messageAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyle破坏性标题:@“消息”处理程序:^(UITableViewRowAction*action,NSIndexPath*indexPath){
[tableActivities deleteRowsAtIndexPaths:@[indexPath]带RowAnimation:UITableViewRowAnimationAutomatic];
}];
return@[messageAction,cancelAction,editAction];
}
-(void)tableView:(UITableView*)tableView提交的编辑样式:(UITableViewCellEditingStyle)行的编辑样式索引路径:(NSIndexPath*)索引路径{
}
在单元格的contentView
中,我放置了一个ui按钮
,该按钮内部有一个uicontrolEventTouchUp
controlEvent
当我通过触摸按钮区域来滑动单元格时,滑动和
ui按钮
事件都会触发。如何控制此操作?您可以通过如下方式检查
按钮中UITableView
的I编辑属性来解决问题
- (void)btnTap:(UIButton*) sender {
if (!self.tableActivities.isEditing) {
//Perform Action
}
}
欢迎快乐编码:)UITableView.canCancelContentTouches
应该可以防止这种情况发生。@Andy:滚动条不起作用吗?