【问题标题】:Drag and Drop into a `UICollectionView` placeholder in iOS 11 Beta 4在 iOS 11 Beta 4 中拖放到“UICollectionView”占位符中
【发布时间】:2017-07-25 03:44:27
【问题描述】:

在 iOS 11 Beta 4 中更改了用于拖放到 UICollectionView 的 API。在 beta 1-3 中,代码如下所示:

let placeholderContext = coordinator.drop(
    item.dragItem,
    toPlaceholderInsertedAt: indexPath,
    withReuseIdentifier: "reuseID",
    cellUpdateHandler: { _ in }
)

在 beta 4 中,引入了UICollectionViewDropPlaceholder。我的代码是

let placeholder = UICollectionViewDropPlaceholder(
    insertionIndexPath: indexPath,
    reuseIdentifier: "reuseID"
)

let placeholderContext = coordinator.drop(item.dragItem, to: placeholder)

我得到这个编译错误:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_UICollectionViewDropPlaceholder", referenced from:
      objc-class-ref in StickerLibraryViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
note: symbol(s) not found for architecture arm64
error: linker command failed with exit code 1 (use -v to see invocation)

除了在 beta 5 之前不使用占位符之外,还有人知道如何在 beta 4 中使用这个占位符吗?

谢谢!

【问题讨论】:

    标签: ios drag-and-drop uicollectionview ios11


    【解决方案1】:

    在 Beta 5 中修复此问题之前,我最终通过进入 Objective-C 运行时解决了此问题。

    在 Obj-C 标头中……

    NS_ASSUME_NONNULL_BEGIN
    
    @interface RKNFactory : NSObject
    
    - (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier;
    
    @end
    
    NS_ASSUME_NONNULL_END
    

    在实施中……

    @import ObjectiveC.runtime;
    
    @implementation RKNFactory
    
    - (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier {
    
        SEL initSelector = NSSelectorFromString(@"initWithInsertionIndexPath:reuseIdentifier:");
        Class placeholderClass = NSClassFromString(@"UICollectionViewDropPlaceholder");
        return [[placeholderClass alloc] performSelector:initSelector  withObject:indexPath withObject:reuseIdentifier];
    }
    
    @end
    

    然后从 Swift 代码中......

    return RKNFactory().placeholder(for: indexPath, resuseIdentifier: reuseIdentifier)
    

    【讨论】:

      【解决方案2】:

      当它处于测试阶段时,我遇到了类似的问题,即本地身份验证未在模拟器架构上编译。

      如果您在构建设置中从有效架构中删除 arm64(或关闭“构建所有架构”),它会编译吗?

      如果他们为模拟器编译了这个符号,但为 arm64 保留了它,唯一的解决方案可能是阻止它在 arm64 上编译并暂时只在模拟器上测试它。

      您还可以将代码临时包装在“#if 块”中,以防止编译器在构建 arm64 时查看它。

      最后,如果您正在为 iOS 11 下的任何 iOS 版本进行构建,请务必暂时关闭这些功能,以防他们忘记标记 API 可用性(这可能会让编译器提供更有用的消息) .

      【讨论】:

      • 不幸的是,它不适用于任何架构。仅仅将它放在#if-block 中不会很好用(我所有的拖放代码都是围绕使用占位符设计的)。幸运的是,深入到 Obj-C 运行时让它工作到 beta 5。
      猜你喜欢
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多