我已阅读了一些有关此问题的问题,但找不到解决方案。将b完成按钮添加到数字键盘
我简单惯于一个完成按钮添加到我的数字小
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardWillShowNotification
object:nil];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)addButtonToKeyboard {
NSLog(@"call");
// 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;
NSLog(@"%d", [tempWindow.subviews count]);
for(int i=0; i<[tempWindow.subviews count]; i++) {
NSLog(@"found");
keyboard = [tempWindow.subviews objectAtIndex:i];
[keyboard addSubview:doneButton];
}
}
- (void)keyboardDidShow:(NSNotification *)note {
// if clause is just an additional precaution, you could also dismiss it
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
[self addButtonToKeyboard];
}
}
此代码:
的NSLog(@ “%d”,[tempWindow.subviews计数]);
始终为0,所以它根本不会添加按钮...任何想法?
我没有看到你在上面的代码中添加按钮到tempWindow的位置,你在别的地方做它吗? – Brian
[keyboard addSubview:doneButton]; 这个,还是不行? –