【发布时间】:2012-04-29 17:04:12
【问题描述】:
我想在 UIWebView 上显示 SQLite 数据库内容。为此,我有一个本地 HTML 文件。在调用 JavaScript 函数的 html 文件中加载正文。 Java Script里面如何调用Objective-c方法。如何从 Objective c 获取数据到 Java Srcipt。
<html>
<head>
<!-- a script inline -->
<script language="JavaScript" TYPE="text/javascript">
<!--
function myJsFunc()
{
//here i want to call objective-c methods.
}
// -->
</script>
</head>
<Body Bgcolor=#800000 onload="myJsFunc(); return true;">
</Body>
</html>
Objective-C 代码 ......
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path;
NSBundle *thisBundle = [NSBundle mainBundle];
path = [thisBundle pathForResource:@"Demo" ofType:@"html"];
// make a file: URL out of the path
NSURL *instructionsURL = [NSURL fileURLWithPath:path];
[myWebView loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
[self.view addSubView:myWebView];
}
-(NSArray*)FetchingDataFromDataBase{
// Code for retriving data from SQlite data Base, and return NSArray;
return myArray;
}
函数myJSFunc()里面,怎么调用-(NSArray*)FetchingDataFromDataBase.
【问题讨论】:
-
script元素上的language属性已被弃用十多年,您现在可以将其关闭。type属性应该是小写的,但坦率地说,你 don't need it 除非你包含一个用 JavaScript 编写的 not 脚本(这是 HTML5 规范正在编纂的领域之一现有的做法,而不是口述新的东西)。
标签: javascript iphone objective-c ios uiwebview