func displayalert(title:String, message:String, vc:UIViewController)
{
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction((UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
self.dismiss(animated: true, completion: nil)
})))
vc.present(alert, animated: true, completion: nil)
}
this is the function i have used.i tried to call it like this,
displayalert1(title:"dsfvasdcs", message:"easfSDXCSDZX", vc:validateOTPViewController())
它返回错误“不良访问”。 vc.present像循环一样运行。我不明白问题是什么。创建全局显示报警功能,并从任何视图控制器调用它
问题是什么? –
将此方法创建为静态方法,并将其类添加到项目的.pch文件中。你将可以访问任何课程。 – Priyal
这是糟糕的编程习惯。将代码放入'UIViewController'的扩展中,删除'vc'参数并删除'present'行中的'vc.'。 – vadian