通知センターにオブザーバーを2回(事故によって)追加することができます。通知を2回取得します。 通知を1つだけ取得することはできますか?より洗練されたソリューションをご存知ですか?NSNotificationCenterによりバグが発生する可能性があります。より洗練されたソリューションをご存知ですか?
これはバグにつながる可能性があるため、この例を示します。
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
}
- (void)keyboardDidShow:(NSNotification *)ntf
{
}
hm ..別の同一のコードを複数回書くと、バグにつながる可能性があります。 – beryllium