Swift - 如何在AppDelegate中更改布局内容

时间:2017-12-28 05:57:42

标签: ios swift3 uiimage appdelegate

我尝试在应用启动时显示提醒(标签式应用)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    let welcomeAlert = UIAlertController(title: "Turn on Bluetooth?", message: "Turn on Bluetooth?", preferredStyle: UIAlertControllerStyle.alert)
    welcomeAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {
    action in self.alertServerClient()
    }))
    welcomeAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))

    let alertWindow = UIWindow(frame: UIScreen.main.bounds)

    alertWindow.rootViewController = UIViewController()
    alertWindow.windowLevel = UIWindowLevelAlert + 1;
    alertWindow.makeKeyAndVisible()

    alertWindow.rootViewController?.present(welcomeAlert, animated: true, completion: nil)
    return true
}

alertServerClient()我希望像

一样更改UIImage
func alertServerClient() {
    let vc = FirstViewController()
    let imgBTOn = UIImage(named: "BT_Button.png")
    vc.btnBT.setImage(imgBTOn, for: .normal)
}

不幸的是,它不起作用并抛出错误

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

是否可以更改AppDelegate的UI内容?

0 个答案:

没有答案