【发布时间】:2014-02-22 21:10:17
【问题描述】:
我正在尝试从带有 UITableView 的弹出窗口调用 javascript 函数,该 UITableView 包含 iPad 中的 NSArray 字体。我遇到的问题是,每当我从 didselectrowatindexpath 调用函数时,它都无法在 UIWebView 中完成任何操作。我能够在 NSLog 中获得适当的信息,但不知何故,两个视图之间的链接失败了。如果我将该功能分配给包含 UIWebView 的视图中的按钮,一切都会很好。我正在使用情节提要,并且 popovervew 和 UIWebView 共享相同的 viewController 类。这可能是我忽略的非常简单的事情,但无论出于何种原因,我都被卡住了。此外,如果我调用一些其他功能,如警报视图,一切都会按预期工作。我真诚地感谢您在此问题上提供的任何帮助。谢谢
这是我在 didselectrowatindexpath 中调用 javascript 函数的方式:
- (void) tableView: (UITableView *) theTableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
UITableViewCell *selectedCell = [self.myTableView cellForRowAtIndexPath:indexPath];
NSString *cellText1 = selectedCell.textLabel.text;
[myWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"tinymce.activeEditor.execCommand('fontName', false, '%@');", cellText1]];
NSLog (@"%@", cellText1);
[self.myTableView deselectRowAtIndexPath: indexPath animated: YES];
}
这是视图中包含将字体设置为“Arial”的 UIWebView 的按钮的代码:
-(IBAction)changeFont:(id)sender{
[myWebView stringByEvaluatingJavaScriptFromString:@"tinymce.activeEditor.execCommand('fontName', false, 'Arial');"];
}
【问题讨论】:
-
绝对奇怪...我希望它可以在任何一个地方工作。如果您在 javascript 中执行 alert(),它会显示什么吗?
标签: javascript ios uitableview uiwebview uipopovercontroller