【发布时间】:2017-07-12 22:49:04
【问题描述】:
我需要从一个字符串中实现一个执行选择器。 选择器必须有一个通知值作为参数。
class ChapterViewController: UIViewController {
var chapterClass:ChapterClass!
func catchNotificationParagraphFinished(notification:Notification) {
let name = "catchNotificationParagraphFinished_\(chapter.className!)"
let selector = NSSelectorFromString(name)
chapterClass.perform(selector, with: notification)
}
}
class ChapterClass: NSObject {
func catchNotificationParagraphFinished_Chapter2(notification:Notification) {}
}
我想我做错了什么,因为我收到了这个错误:
[ISAMGAME.ChapterClass catchNotificationParagraphFinished_Chapter2]:无法识别的选择器发送到实例 0x600000052c60
*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[ISAMGAME.ChapterClass catchNotificationParagraphFinished_Chapter2]:无法识别的选择器 发送到实例 0x600000052c60**
我也试过了:
func catchNotificationParagraphFinished_Chapter2(_ notification:Notification) {}
并且还尝试使用:
let name = "catchNotificationParagraphFinished_\(chapter.className!):"
let selector = Selector((name))
我的方法基于:
【问题讨论】:
标签: ios swift string performselector