如何为通知对象设置'UIDevice.currentDevice()'?

时间:2014-07-29 05:52:56

标签: ios notifications swift uidevice

当我添加设备方向更改通知时,如下所示:

NSNotificationCenter.defaultCenter().addObserver(self,
        selector: Selector(layoutPages),
        name: UIDeviceOrientationDidChangeNotification as String!,
        object: UIDevice.currentDevice())

我收到错误' UIDevice与anyobject'不完全相同,那么如何解决?

1 个答案:

答案 0 :(得分:0)

你的第二个参数有问题,它应该是一个字符串。此外,将UIDevice向上转换为AnyObject将有所帮助:

NSNotificationCenter.defaultCenter().addObserver(self,
    selector: Selector("layoutPages"),
        name: UIDeviceOrientationDidChangeNotification as NSString!,
      object: UIDevice.currentDevice() as AnyObject)