我正在尝试通过 JavaScipt 获取已加载网页的标题,并将其作为 UIActionSheet 的标题,如下所示:
我目前在ViewController.m中的内容:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *webTitle = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
- (IBAction)showActionSheet:(id)sender {
// webTitle.text receives errors
UIActionSheet *actionsheet = [[UIActionSheet alloc]initWithTitle:webTitle delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Share...", @"Bookmarks", @"Read Later", @"Add to Bookmarks", @"Settings", nil];
actionsheet.actionSheetStyle = UIBarStyleBlackTranslucent;
[actionsheet showInView:self.view];
NSLog(@"Action Menu opened");
}
编辑:我也收到这些警告。
EDIT2:通过 javascript 警报评估代码工作正常。