UiSwipeActionsConfiguration-单元在首次启动时会重新加载自身

时间:2018-08-02 06:15:52

标签: objective-c xcode uitableview uitableviewrowaction uiswipeactionsconfiguration

The strange behavior:

Cell在第一次启动时会重新加载其操作,但是 trailingSwipeActionsConfigurationForRowAtIndexPath 仅被调用一次,有什么想法吗?

代码:

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {

UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

   //...

}];

UIContextualAction *moreAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

    //...

    completionHandler(YES);
}];

deleteAction.backgroundColor = [UIColor colorWithRed:(245/255.0) green:(78/255.0) blue:(70/255.0) alpha:1];
moreAction.backgroundColor = [UIColor colorNamed:@"CL_LightGray_2"];

UISwipeActionsConfiguration *SwipeActions = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction,moreAction]];
SwipeActions.performsFirstActionWithFullSwipe=false;
return SwipeActions;

}

1 个答案:

答案 0 :(得分:0)

我发现了问题!对于以后遇到相同问题的所有人:

    [UIView animateWithDuration:1.0 animations:^{

    //...

  }];

在其他地方执行此代码后,单元的操作也会重新加载。这会产生奇怪的行为。