iOS11下UITableViewCell左滑删除仅能触发一次问题求助
Hey there, let's dig into this frustrating iOS 11 swipe action bug you're facing. That NSForwarding warning is actually the key clue here—let's break it down step by step.
首先理解警告的含义
The warning *** NSForwarding: warning: method signature and compiler disagree on struct-return-edness of 'prepareWithSwipeDirection:configuration:' tells us there's a mismatch between how the compiler expects the prepareWithSwipeDirection:configuration: method to behave, and how it's actually implemented somewhere in your code. Specifically:
- The system's method signature expects it to not return a struct, but your code (likely a category) has an implementation that the compiler thinks does return a struct (or vice versa). This mismatch breaks the swipe action system after the first use.
核心解决方案:修复方法签名不匹配
This is almost always caused by an incorrect category implementation on UITableViewCell, UISwipeActionsConfiguration, or a related class. Here's what to do:
全局搜索方法名
Use Xcode's search bar to look forprepareWithSwipeDirection:configuration:across your entire project. You're looking for any category or custom class that overrides this system method.对比并修正方法签名
The correct system method signature for iOS 11+ is:- (void)prepareWithSwipeDirection:(UISwipeActionsConfigurationDirection)direction configuration:(UISwipeActionsConfiguration *)configuration;If you find an implementation that returns a struct (like
CGSize) or has a different return type/parameter list, delete that implementation (if it's unnecessary) or fix the signature to match the system's exactly.
验证你的滑动配置实现
Even if you've implemented the iOS 11 swipe methods, double-check for these common issues:
Make sure your trailingSwipeActionsConfigurationForRowAtIndexPath method follows this pattern (with proper completion handling):
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { // 创建删除动作 UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"Delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { // 执行你的删除逻辑 [self.dataArray removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; // 必须调用completionHandler,否则手势状态会卡住 completionHandler(YES); }]; UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]]; // 可选:允许全屏左滑直接触发删除 config.performsFirstActionWithFullSwipe = YES; return config; }
Key checks here:
- You're returning a valid
UISwipeActionsConfigurationinstance - You're calling the
completionHandlerin your action handler (this is critical to reset the swipe state) - You're not mixing conflicting logic between the old
commitEditingStylemethod and the new swipe configuration (though they can coexist, ensure they don't interfere)
最后一步:清理缓存
Sometimes Xcode's derived data can cause weird signature mismatches. Try:
- Deleting your project's Derived Data (Window → Projects → Select your project → Delete Derived Data)
- Restarting Xcode
- Doing a clean build (Cmd+Shift+K) then a full build (Cmd+B)
内容的提问来源于stack exchange,提问作者Maxime B

