iOS 11 SDK 引入了两个新的 UITableView 方法来处理滑动操作:
- leadingSwipeActionsConfigurationForRowAtIndexPath
- trailingSwipeActionsConfigurationForRowAtIndexPath
目标-C:
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
滑动动作基于新的 UIContextualAction 类:
@class UIContextualAction;
// call the completionHandler to reset the context to its normal state (e.g. when swiping, resets to unswiped state)
// pass YES to the completionHandler if the action was actually performed, to show a visual indication of the successful completion
typedef void (^UIContextualActionHandler)(UIContextualAction *action, __kindof UIView *sourceView, void(^completionHandler)(BOOL actionPerformed));
typedef NS_ENUM(NSInteger, UIContextualActionStyle) {
UIContextualActionStyleNormal,
UIContextualActionStyleDestructive
} NS_SWIFT_NAME(UIContextualAction.Style) API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
UIKIT_EXTERN API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos)
@interface UIContextualAction : NSObject
+ (instancetype)contextualActionWithStyle:(UIContextualActionStyle)style title:(nullable NSString *)title handler:(UIContextualActionHandler)handler;
@property (nonatomic, readonly) UIContextualActionStyle style;
@property (nonatomic, copy, readonly) UIContextualActionHandler handler;
@property (nonatomic, copy, nullable) NSString *title;
@property (nonatomic, copy, nullable) UIColor *backgroundColor; // a default background color is set from the action style
@property (nonatomic, copy, nullable) UIImage *image;
@end
我试图像这样将其“翻译”为 Delphi:
{UIContextualAction}
const
UIContextualActionStyleNormal = 0;
UIContextualActionStyleDestructive = 1;
type
UIContextualAction = interface;
UIContextualActionStyle = integer;
UIContextualCompletionHandler = ???? // <------------------------
UIContextualActionHandler = procedure(action: UIContextualAction; sourceView: UIView; completionHandler: UIContextualCompletionHandler) of object;
UIContextualActionClass = interface(NSObjectClass)
['{F341A178-2950-4D0A-9EF2-DCDEAB76FF81}']
function contextualActionWithStyle(style: UIContextualActionStyle; title: NSString; handler: UIContextualActionHandler): Pointer; cdecl;
end;
UIContextualAction = interface(NSObject)
['{C5B4CB53-0655-41FA-B48E-D4FB0E9A54FB}']
function title: NSString; cdecl;
function backgroundColor: UIColor; cdecl;
function image: UIImage; cdecl;
procedure setTitle(title: NSString); cdecl;
procedure setBackgroundColor(backgroundColor: UIColor); cdecl;
procedure setImage(image: UIImage); cdecl;
end;
TUIContextualAction = class(TOCGenericImport<UIContextualActionClass, UIContextualAction>);
每个 UIContextualAction 都被分配了一个指向代码块 (UIContextualActionHandler) 的指针。此代码块获取另一个代码块(completionHandler),作为参数传递。这个参数代码块非常重要,因为它确保动作的正确视觉完成。更确切地说是我的问题:如何定义一个以另一个代码块作为参数的完成代码块?