これをグーグルで一晩中過ごしましたが、まだサイコロはありません。埋め込まれた html/javascript テスト ファイルに文字列を渡そうとしています。エラーは発生していませんが、次のいずれかの関数も取得していません:[
コードに関して私が得たものは次のとおりです。
DetailedController.h
#import <UIKit/UIKit.h>
@interface DetailController : UIViewController<UIWebViewDelegate>{
UIWebView *webView;
}
@property (nonatomic, strong) NSArray *Detailinfo;
@property (nonatomic, strong) IBOutlet UILabel *DetailName;
@property (nonatomic, strong) IBOutlet UILabel *dob;
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@end
DetailedController.m
#import "DetailController.h"
@interface DetailController ()
@end
@implementation DetailController
@synthesize webView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.hidesBackButton = YES;
UINavigationItem *topBar;
topBar.title = self.Detailinfo[0];
self.DetailName.text = self.Detailinfo[0];
self.dob.text = self.Detailinfo[1];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"javascriptTest" ofType:@"html"]];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestObj];
self.webView.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"loadText(%@)", self.Detailinfo[1]]];
}
@end
および HTML ファイル javascriptTest.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test JavaScript</title>
<script>
function loadText(txtString)
{
var divd = document.createElement('div');
divd.innerHTML = "<p>" + txtString + "</p>";
document.body.appendChild(divd);
document.getElementById('info').value = "";
}
</script>
</head>
<body>
loaded
<!--
<input type="text" id="info" />
<button onclick="loadText(document.getElementById('info').value)"> Load Text </button>
-->
</body>
</html>
どんな助けでも大歓迎です:]
更新 @ACB が言ったように、javascript 関数内に '' を追加するだけで済みました@"loadText('%@')"