是我的代碼完成按鈕不工作
- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows]objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
} else {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
,但我無法添加完成按鈕,經過與斷點交叉檢查後,我觀察到控制不進入if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
條件。 我正在使用IOS5。
爲什麼objectAtIndex:1? – stark
@stark其實我正在學習本教程,http://www.neoos.ch/blog/37-uikeyboardtypenumberpad-and-the-missing-return-key – Valli
你確定這個方法在鍵盤出現時被調用嗎? – Novarg