我试图声明一个函数来在我的应用程序中显示警报。为了避免重复工作,我试图为我的所有应用程序使用相同的功能。我试图通过创建一个具有函数showNotification的类来实现这一点。但是当我创建该类的对象并调用方法时,没有任何反应。我怎样才能做到这一点?在所有视图控制器中创建警报功能 - swift
class SharedPropertiesAndMetods : UIViewController {
func showNotification(title: String, message: String)
{
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "تائید", style: .default, handler: nil)
alertController.addAction(defaultAction)
present(alertController, animated: true, completion: nil)
}
}
添加此方法的UIViewController – Anuraj
@HosAp的延伸有4个答案。他们都没有帮助吗? –
@GaneshKumar是的,作为扩展添加是一个好主意 –