Ios 在委托方法中传递的类对象变为<;未初始化>;在Mac催化剂中
在实现协议的类中,委托方法中传递的对象未初始化。但同一对象在从中调用委托的类中具有有效地址。只有在maccatalyst中才会出现这种情况,同样的代码在iOS和iPadOS中也能完美运行 议定书声明Ios 在委托方法中传递的类对象变为<;未初始化>;在Mac催化剂中,ios,xcode,protocols,swift5,mac-catalyst,Ios,Xcode,Protocols,Swift5,Mac Catalyst,在实现协议的类中,委托方法中传递的对象未初始化。但同一对象在从中调用委托的类中具有有效地址。只有在maccatalyst中才会出现这种情况,同样的代码在iOS和iPadOS中也能完美运行 议定书声明 protocol ASPatientSearchDelegate: class { func moveToPaitentProfileScreen(patient: ASCardEntity) } weak var delegate: ASPatientSearchDelegat
protocol ASPatientSearchDelegate: class {
func moveToPaitentProfileScreen(patient: ASCardEntity)
}
weak var delegate: ASPatientSearchDelegate? = nil
class ASAppointmentViewController: ASBaseViewController {
var searchViewController: ASPatientSearchViewController?
}
委托变量声明
protocol ASPatientSearchDelegate: class {
func moveToPaitentProfileScreen(patient: ASCardEntity)
}
weak var delegate: ASPatientSearchDelegate? = nil
class ASAppointmentViewController: ASBaseViewController {
var searchViewController: ASPatientSearchViewController?
}
代理调用
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let patient = self.searchResults[indexPath.row]
self.delegate?.moveToPaitentProfileScreen(patient: patient)
}
方法实现
extension ASAppointmentViewController: ASPatientSearchDelegate {
func moveToPaitentProfileScreen(patient: ASCardEntity) {
guard let json = patient.details as? JSON else { return }
}
}
在ASAppointmentViewController中分配的代理
@IBAction func searchButtonAction(_ sender: UIButton) {
let searchViewController = ASPatientSearchViewController(nibName: ASPatientSearchViewController.className, bundle: nil)
searchViewController.popoverPresentationController?.delegate = self
searchViewController.modelController.delegate = self
}
使用的类
class ASCardEntity: NSObject {
var details: Any?
}
这是实例范围问题。我已将ASPatientSearchViewController实例变量声明为类范围 实例变量声明
protocol ASPatientSearchDelegate: class {
func moveToPaitentProfileScreen(patient: ASCardEntity)
}
weak var delegate: ASPatientSearchDelegate? = nil
class ASAppointmentViewController: ASBaseViewController {
var searchViewController: ASPatientSearchViewController?
}
我改了下面的代码
@IBAction func searchButtonAction(_ sender: UIButton) {
let searchViewController = ASPatientSearchViewController(nibName: ASPatientSearchViewController.className, bundle: nil)
searchViewController.popoverPresentationController?.delegate = self
searchViewController.modelController.delegate = self
}
到