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