gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 09:20:30 25 4
gpt4 key购买 nike

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

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

我收到错误“UIDevice is not identical to anyobject”,那么如何修复它?

最佳答案

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

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

关于ios - 如何设置通知对象为 'UIDevice.currentDevice()'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25008975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com