我正在编写一个代码,这个代码是由我公司的其他人留下的,有些东西我不明白为什么他这样做:我正在设置我的键盘监听器{{1} }
代码:
[self setKeyboardListenersInRegisterView]
但是,他在这里称这个功能:
- (void)setKeyboardListenersInRegisterView {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onKeyboardHideInRegisterView:)
name:UIKeyboardWillHideNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onKeyboardShowInRegisterView:)
name:UIKeyboardWillShowNotification
object:nil];
}
所以,你们知道为什么他在main_queue中调用函数而不是在它之外?重要的是,我的键盘通知的选择器正在执行动画(只是将视图设置为一些像素,以便查看用户编写的内容)。
答案 0 :(得分:3)
如果您试图以任何方式,形状或形式以不同于主线程的方式与接口对象通话,那么您做错了。在Xcode 9中,你实际上会因为这样做而感到害怕(假设你的方案中已经打开了主线程检查器,你绝对应该这样做。)