gpt4 book ai didi

iphone - 如何替换 iOS 6 上 UIWebView 键盘下工具栏上的按钮?

转载 作者:行者123 更新时间:2023-12-03 21:16:34 25 4
gpt4 key购买 nike

如何在 iOS 6 上替换 UIWebView 键盘下工具栏上的按钮?

以下代码在 iOS 5.1 上运行良好,但在 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 上的错误:

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)

非常感谢您的帮助!

最佳答案

UIWebFormAccessory 不再是 iOS6 上的 UIToolbar。不过,它包含您正在寻找的 UIToolbar。使用类似以下内容在任一操作系统版本上查找它...

+ (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;
}

关于iphone - 如何替换 iOS 6 上 UIWebView 键盘下工具栏上的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12622931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com