Vì vậy, bàn phím numpad không đi kèm với nút 'Xong' hoặc 'Tiếp theo' theo mặc định, vì vậy tôi muốn thêm một nút. Trong iOS 6 trở xuống, có một số thủ thuật để thêm nút vào bàn phím nhưng chúng dường như không hoạt động trong iOS 7.
Đầu tiên tôi đăng ký bàn phím hiển thị thông báo
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
Sau đó, tôi cố gắng thêm một nút khi bàn phím hiển thị:
- (void)keyboardWillShow:(NSNotification *)note
{
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
doneButton.frame = CGRectMake(0, 50, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton addTarget:self action:@selector(dismissKeyboard) 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 view found; add the custom button to it
if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
Nhưng vòng lặp for không chạy vì nó không tìm thấy bất kỳ lượt xem phụ nào. Bất kỳ đề xuất? Tôi không thể tìm thấy bất kỳ giải pháp nào cho iOS7, vậy có cách nào khác mà tôi phải thực hiện việc này không?
Chỉnh sửa: Cảm ơn vì tất cả các đề xuất cho những người thanh công cụ nhưng tôi không muốn đi xuống tuyến đường đó vì tôi khá nghèo về không gian (và nó hơi xấu).