iOS (Swift) - 应用程序委托 window 的根视图控制器在模拟器中工作,但在 phone 上加载应用程序时失败
iOS (Swift) - Casting root view controller of the app delegate's window works in simulator, but fails when app is loaded on phone
当我 运行 我的应用程序使用以下代码行(在 AppDelegate.swift 文件内)时:
func locationManager(manager: CLLocationManager!,
didRangeBeacons beacons: [AnyObject],
inRegion region: CLBeaconRegion!) {
let viewController:ViewController = window!.rootViewController as! ViewController
viewController.beacons = beacons as! [CLBeacon]
viewController.tableView.reloadData()
...... }
只有当我 运行 模拟器中的应用程序时,它才会 运行 完美无缺。否则,当我 运行 我 phone 上的应用程序时,我得到这个 运行 时间错误:
Could not cast value of type 'UITableViewController' (0x198be57d0) to
'beaconTest.ViewController' (0x1000e15d0).
ViewController 是 UITableViewController 的子类,定义如下:
window 的根视图控制器在哪里设置?
如果它在故事板中,请确保根视图控制器的 class 是 ViewController
而不是 UITableViewController
。
当我 运行 我的应用程序使用以下代码行(在 AppDelegate.swift 文件内)时:
func locationManager(manager: CLLocationManager!,
didRangeBeacons beacons: [AnyObject],
inRegion region: CLBeaconRegion!) {
let viewController:ViewController = window!.rootViewController as! ViewController
viewController.beacons = beacons as! [CLBeacon]
viewController.tableView.reloadData()
...... }
只有当我 运行 模拟器中的应用程序时,它才会 运行 完美无缺。否则,当我 运行 我 phone 上的应用程序时,我得到这个 运行 时间错误:
Could not cast value of type 'UITableViewController' (0x198be57d0) to 'beaconTest.ViewController' (0x1000e15d0).
ViewController 是 UITableViewController 的子类,定义如下:
window 的根视图控制器在哪里设置?
如果它在故事板中,请确保根视图控制器的 class 是 ViewController
而不是 UITableViewController
。