view.selectNumberTF.text = [NSString stringWithFormat:@"%@",xYGoodsInfo.qidingCount];
//增加通知中心監(jiān)聽(tīng),當(dāng)鍵盤(pán)出現(xiàn)或消失時(shí)收出消息
[[NSNotificationCenter defaultCenter] addObserver:view selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:view selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
return view;
}
observer是實(shí)例的view,而不是self,self的話(huà)是指類(lèi)了,本來(lái)統(tǒng)一用self(類(lèi))也行,但是
- (void)keyboardWillShow:(NSNotification *)notification{
//取得鍵盤(pán)最后的frame
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat height = keyboardFrame.origin.y;
if([_delegate respondsToSelector:@selector(keyboardWillShow:)]){
[_delegate keyboardWillShow:height];
}
}
這個(gè)是實(shí)例方法,如果用self(類(lèi)) 不用view(實(shí)例)會(huì)閃退,
reason: '+[XYOtherIsNOValueView keyboardWillShow:]: unrecognized selector sent to class 0x1111dd010'
類(lèi)里沒(méi)這個(gè)方法(因?yàn)樗菍?shí)例的),
就算可以把keyboardWillShow改成類(lèi)方法,但是里面的delegate不能放到類(lèi)方法里面,

8@}6K2VL(5%W)99UA796P3O.jpg
所以還是乖乖用實(shí)例來(lái)通知吧
ps:
- (void)dealloc{
//
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
self寫(xiě)在類(lèi)方法里代表類(lèi),寫(xiě)在實(shí)例方法里代表實(shí)例。
傳值
ps:記得移除觀察者
- (void)dealloc{
//
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
貌似只有觀察者才有移除一說(shuō),發(fā)布的沒(méi)有