gpt4 book ai didi

ios - NSNotificationcenter 没有成员名称 'defaultCenter"错误 -Swift

转载 作者:行者123 更新时间:2023-11-28 10:25:57 34 4
gpt4 key购买 nike

<分区>

尝试快速添加键盘观察器并出现错误

NSNotificationcenter 没有成员名称“defaultCenter”

使用

NSNotificationCenter().defaultCenter().addObserver(self, selector: Selector("keyboardWillAppear"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter().defaultCenter().addObserver(self, selector: Selector("keyboardWillHide"), name: UIKeyboardWillHideNotification, object: nil)

根据以下建议 NSNotificationCenter addObserver in Swift Swift: Keyboard Observer via NSNotificationCenter doesn't work

如果我删除 defaultCenter 我不会收到错误,但也不会观察到键盘

NSNotificationCenter().addObserver(self, selector: Selector("keyboardWillAppear"), name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter().addObserver(self, selector: Selector("keyboardWillHide"), name: UIKeyboardWillHideNotification, object: nil)

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