Stringからperformセレクタを実装する必要があります。 セレクタは、パラメータとして通知値を持たなければなりません。Stringからパラメータを指定してperformセレクタを実装する
[ISAMGAME.ChapterClass catchNotificationParagraphFinished_Chapter2]: unrecognized selector sent to instance 0x600000052c60
*Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ISAMGAME.ChapterClass catchNotificationParagraphFinished_Chapter2]: unrecognized selector sent to instance 0x600000052c60**
私もしてみました:
func catchNotificationParagraphFinished_Chapter2(_ notification:Notification) {}
も使用してみました:
let name = "catchNotificationParagraphFinished_\(chapter.className!):"
let selector = Selector((name))
私はこのエラーを得たので
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) {}
}
私は、私が何か間違ったことをやっていると仮定します
私のアプローチは以下の通りです:
私は本当にStringからセレクタを作成する必要があります。文字列に応じて、私はcatchNotificationParagraphFinished_Chapter2またはcatchNotificationParagraphFinished_Chapter3などを呼び出します...私は多くの "if"条件を持つことを避けたいと思います。 – cmii
私は、これを反映するために私の答えを編集しています。 – genghiskhan
同じクラッシュ "[ISAMGAME.ChapterClass catchNotificationParagraphFinished_Chapter2(notification :)]:インスタンスに送信されたセレクタが認識されません" :( – cmii