0
我試圖將大部分代碼移動到另一個文件;我相信我已經做到了,但是,我在調用函數時遇到了問題。UIBarButtonItem在調用時未在另一個類中調用函數
我有兩個文件:
scannerBrain.swift
var parentView = UIViewController()
func startScan(){
//The code I want to execute is here
}
scannerViewController.swift
let scanner = scannerBrain()
scanner.parentView = self
let rightButton = UIBarButtonItem(barButtonSystemItem: .add, target: scanner, action: #selector(scanner.startScan))
navigationItem.rightBarButtonItem = rightButton
編譯沒有問題,除了startScan
不會被調用。我試圖改變rightButton
的目標self
,但造成的unrecognised selector sent to instance
崩潰感謝所有幫助
謝謝了!你幫了很多忙 – Will