- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 UIView
。该应用程序正在使用 ARC。 UIView
用于多个 View Controller 。在 UIView
中添加了一个 UIKeyboardDidHideNotification
的监听器。监听器在某些 View Controller 上工作正常,而在其他 View Controller 上它会使应用程序崩溃。特别是当我在第一个 View Controller 中使用后在第二个 View Controller 中使用时。错误是
* -[appname keyboardWillHide]: message sent to deallocated instance 0xb9c2760
在某些情况下,监听器会被调用两次。
我在 uiview drawrect 方法中添加的代码是:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
监听器的代码是
-(void)keyboardWillHide
{
if(boolisViewlifted)
{
CGRect newFrame=self.frame;
newFrame=CGRectMake(self.frame.origin.x, self.frame.origin.y+250, self.frame.size.width, self.frame.size.height);
self.frame=newFrame;
boolisViewlifted=false;
}
}
uiview 出现在调用 View Controller 的顶部。请让我知道导致此错误的原因以及解决方法。
最佳答案
由于内存警告,您的 View 正在卸载。您需要覆盖 dealloc 方法并删除所有 View 中所有通知的观察者,其中您添加了通知观察者。
//do add in all views
-(void)dealloc
{
//[super dealloc];//As you are using ARC don't call super's dealloc
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
关于iphone - UIKeyboardDidHideNotification 错误应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13777920/
我正在使用 UIView。该应用程序正在使用 ARC。 UIView 用于多个 View Controller 。在 UIView 中添加了一个 UIKeyboardDidHideNotificati
我的应用程序的一个目标是管理多个自定义输入 View (来自 nibs)以及常规系统键盘。一个或另一个将永远存在。 (在示例代码中,我只管理一个 Nib + 系统键盘)。 更换键盘时,我想保留您在系统
我有可编辑的 UITextView 并且键盘关闭模式是交互式的。此外,我的 Controller 正在监听两个通知:UIKeyboardWillShowNotification、UIKeyboardW
我是一名优秀的程序员,十分优秀!