【发布时间】:2014-08-16 07:17:54
【问题描述】:
我有这种方法可以在键盘出现时转移我的文本字段:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- (void)keyboardWillShow:(NSNotification *)notification {
self.scrollView.contentOffset = CGPointMake(0.0f, keyboardShift);
}
然后我尝试使用块方法代替:
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
self.scrollView.contentOffset = CGPointMake(0.0f, keyboardShift);
}];
但是,使用这种方法,我在块内设置了一个断点,但它没有被调用。有什么我想念的吗?为什么这种方法不起作用,而另一种方法起作用?
【问题讨论】:
标签: ios objective-c objective-c-blocks nsnotificationcenter