我可能錯過了一些東西...... 首先,我從UITextField
繼承,並增加了點擊手勢識別器的UITextField
(在指定的初始化器):當文本框成爲第一個響應,手勢識別器沒有反應,甚至辭職後
UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pressed:)];
[self addGestureRecognizer:ges];
-(void)pressed:(id)sender
{
didPressed = YES;
[self becomeFirstResponder];
}
然後我把我的viewController是文本框的委託並實現這一點:
- (BOOL)textField:(UIOneLetterTextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSLog(@"Key Pressed %@", string);
textField.text = string;
[textField resignFirstResponder];
UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:textField action:@selector(pressed:)];
[textField addGestureRecognizer:ges];
[self gotoNextTextfield:textField.cellLoc];
return NO;
}
從這一點來說,出於某種原因,pressed:
不會被調用磨片點擊textField。 任何想法爲什麼?
有可能是其他手勢識別器干擾它。嘗試設置您的手勢識別器的委託,實現所有委託方法,並查看哪些被調用。 –
爲什麼要在派生類的指定初始化程序中添加兩次手勢識別器,然後再在委託方法中添加手勢識別器? – blackbird
我再次添加,因爲我絕望......亞倫,你的建議是有道理的...我會給它一個機會 – Yony