【问题标题】:Swift usage of selector not worked快速使用选择器不起作用
【发布时间】:2014-12-01 07:45:27
【问题描述】:

我在 Swift 中创建了 UISwipeGestureRecognizer 对象。下面一行没有编译错误/警告。清理和构建应用程序完美。

let rightSwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, 
                                  action: "handleGesture:")
                                  ^^^^^ Error Part ^^^^^

但它在运行时给出异常。

dyld: lazy symbol binding failed: Symbol not found: __TFSS37_convertFromBuiltinUTF16StringLiteralfMSSFTBp17numberOfCodeUnitsBw_SS
Referenced from:<AppPath>.app/AppName
Expected in: <AppPath>.app/Frameworks/libswiftCore.dylib

这里&lt;AppPath&gt;是模拟器的应用路径。

操作系统:Mac OS X Yosemite 10.10

Xcode 版本:Xcode 6.0.1 (6A317)

我尝试过的;

我能够找出问题出在action: "handleGesture:" 部分。所以我猜这里没有使用正确的选择器。

我尝试了Selector,但没有完成。

  1. NSSelectorFromString("handleGesture:")
  2. Selector("handleGesture:")
  3. Selector.convertFromStringLiteral("handleGesture:")

编辑:

相同的行/代码适用于其他应用程序。我无法弄清楚为什么它停止从这一行执行,因为相同的代码适用于其他应用程序。

【问题讨论】:

  • 将方法标记为 public 或 @obcj 应该可以工作。这样它的名字就不会被破坏。
  • 现在解决了。实际上这个问题与链接有关。我使用了一些开源库,并且我猜想该库的引用已损坏或无法正常工作。只需删除他们的引用并重新连接即可解决此问题。

标签: ios swift selector osx-yosemite xcode6.0.1


【解决方案1】:

试试这个对我有用

var swipeEdit:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("selector:"))
swipeEdit.direction = UISwipeGestureRecognizerDirection.Left;
element.addGestureRecognizer(swipeEdit);

更多细节请通过堆栈溢出中的线程

dyld: Symbol not found: error how to resolve this issue

【讨论】:

  • 检查已编辑的问题,您的代码有效,但问题在应用程序端。
  • 您提供的链接帮助我找出原因。
  • 是的,这很好。快乐的编码。
猜你喜欢
  • 2016-11-16
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 2015-12-28
  • 2016-06-02
  • 1970-01-01
  • 2016-04-03
  • 1970-01-01
相关资源
最近更新 更多