【问题标题】:How to set the 'UIDevice.currentDevice()' for object of notification?如何为通知对象设置“UIDevice.currentDevice()”?
【发布时间】:2014-09-20 10:49:40
【问题描述】:
当我添加设备方向更改的通知时,如下所示:
NSNotificationCenter.defaultCenter().addObserver(self,
selector: Selector(layoutPages),
name: UIDeviceOrientationDidChangeNotification as String!,
object: UIDevice.currentDevice())
我收到一个错误“UIDevice 与任何对象不同”,那么如何修复它?
【问题讨论】:
标签:
ios
notifications
swift
uidevice
【解决方案1】:
你的第二个参数有问题,它应该是一个字符串。此外,将 UIDevice 向上转换为 AnyObject 也会有所帮助:
NSNotificationCenter.defaultCenter().addObserver(self,
selector: Selector("layoutPages"),
name: UIDeviceOrientationDidChangeNotification as NSString!,
object: UIDevice.currentDevice() as AnyObject)