如何更换在iOS 6下一个UIWebView键盘工具栏上的按钮? [英] How to replace buttons on a toolbar under UIWebView keyboard on iOS 6?
本文介绍了如何更换在iOS 6下一个UIWebView键盘工具栏上的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
键盘上的iOS 6如何替换下的UIWebView
工具栏上的按钮?
How to replace buttons on a toolbar under UIWebView
keyboard on iOS 6?
以下code正常工作在iOS 5.1,但在iOS 6不工作:
The following code works fine on iOS 5.1 but doesn't work on iOS 6:
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
for (UIView *possibleFormView in [keyboardWindow subviews]) {
// iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
if ([[possibleFormView description] rangeOfString:@"UIPeripheralHostView"].location != NSNotFound) {
for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([[subviewWhichIsPossibleFormView description] rangeOfString:@"UIWebFormAccessory"].location != NSNotFound) {
UIBarButtonItem *buttonDone =[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(pressDone)];
NSArray *itemsArray;
itemsArray = [NSArray arrayWithObjects:buttonDone, nil];
[(UIToolbar*)subviewWhichIsPossibleFormView setItems:itemsArray];
}
}
}
}
在iOS 6中的错误:
The error on iOS 6:
2012-09-27 16:31:13.537 Linux[2633:907] -[UIWebFormAccessory setItems:]: unrecognized selector sent to instance 0x1d886ad0
2012-09-27 16:31:13.540 Linux[2633:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIWebFormAccessory setItems:]: unrecognized selector sent to instance 0x1d886ad0'
*** First throw call stack:
(0x361032a3 0x3441397f 0x36106e07 0x36105531 0x3605cf68 0x775c5 0x33bbda6f 0x360d85df 0x360d8291 0x360d6f01 0x36049ebd 0x36049d49 0x365862eb 0x37428301 0x7538d 0x75328)
libc++abi.dylib: terminate called throwing an exception
(lldb)
非常感谢您的帮助!
Thanks a lot for the help!
推荐答案
UIWebFormAccessory不再是iOS6的一个UIToolbar。它的包含的您正在寻找的,虽然UIToolbar。使用类似下面找到它无论是操作系统版本...
UIWebFormAccessory is no longer a UIToolbar on iOS6. It contains the UIToolbar you're looking for, though. Use something like the following to find it on either OS version...
+ (UIToolbar *)findVirginWebKeyboardToolbar:(UIView *)parent
{
if ([parent isKindOfClass:[UIToolbar class]]) {
// the stock toolbar contains a single item with a UISegmentedControl customView.
UIToolbar *tb = (UIToolbar *)parent;
if ([tb.items count] == 1 && [((UIBarButtonItem *)[tb.items objectAtIndex:0]).customView isKindOfClass:[UISegmentedControl class]]) {
return tb;
}
}
for (UIView *view in parent.subviews) {
UIToolbar *tb = [self findVirginWebKeyboardToolbar:view];
if (tb) return tb;
}
return nil;
}
这篇关于如何更换在iOS 6下一个UIWebView键盘工具栏上的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文