OC 调用javaScript建议详情页面

来源:互联网 发布:官方mac os 10.9.5 编辑:程序博客网 时间:2024/05/29 23:23

////  ViewOpinionDetailController.m//  JiuZhouDianTi-Admin////  Created by 宇航 on 2017/7/6.//  Copyright © 2017年 JiuZhouDianTi. All rights reserved.//#import "ViewOpinionDetailController.h"#import "HWDConstant.h"#import "NSDate+KHDateTool.h"#import "KHMBProgressHUD.h"@interface ViewOpinionDetailController ()<UIWebViewDelegate>@property(nonatomic,weak) UIWebView * webView;@property(nonatomic,weak) MBProgressHUD * hud;@property(nonatomic,weak) UILabel * timeLabel;@property(nonatomic,weak) UILabel * userLabel;@property(nonatomic,weak) UITextView * textView;@end@implementation ViewOpinionDetailController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    self.title = @"建议详情";    self.view.backgroundColor = HWDColor(254, 255, 255);    [self setwebView];}- (void)setwebView{    UIWebView*webV=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-64)];    _webView=webV;    //webV.dataDetectorTypes=UIDataDetectorTypeNone;    webV.backgroundColor=[UIColor groupTableViewBackgroundColor];    webV.delegate=self;    NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];    NSString *path = [[NSBundle mainBundle] pathForResource:@"feedbackdetail" ofType:@"html"];    NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];    [webV loadHTMLString:html baseURL:baseURL];    [self.view addSubview:webV];        MBProgressHUD*hud = [KHMBProgressHUD showHudInView:self.view];    _hud=hud;}- (void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:animated];    self.navigationController.navigationBar.translucent=NO;}- (void)viewDidDisappear:(BOOL)animated{    [super viewDidDisappear:animated];    self.navigationController.navigationBar.translucent=YES;}- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{    self.navigationController.navigationBar.translucent=NO;    NSURL *URL = request.URL;    HWDLog(@"%@",URL);    HWDLog(@"Scheme: %@",[URL scheme]);    HWDLog(@"Host: %@", [URL host]);    HWDLog(@"Port: %@", [URL port]);    HWDLog(@"Path: %@", [URL path]);    if ([[URL scheme] isEqualToString:@"tel:18253563669"]) {        return NO;    }    return YES;}#pragma mark - UIWebViewDelegate- (void)webViewDidStartLoad:(UIWebView *)webView{}- (void)webViewDidFinishLoad:(UIWebView *)webView{    [_hud hide:YES];    [self getData];}- (void)getData{    // 获取位置信息    // 将结果返回给js    NSString *jsStr = [NSString stringWithFormat:@"setFeedbackTime('%@')",[NSDate changeServeDateStringToNormal:_opinion.creatTime]];    [self.webView stringByEvaluatingJavaScriptFromString:jsStr];    //    setUserName    NSString * userName = [NSString stringWithFormat:@"用户:%@  联系方式%@",_opinion.userDto.fullName,_opinion.userDto.userName];    NSString *jsStr2 = [NSString stringWithFormat:@"setUserName('%@')",userName];    [self.webView stringByEvaluatingJavaScriptFromString:jsStr2];        //    NSString *jsStr3 = [NSString stringWithFormat:@"setFeedbackContent('%@')",_opinion.feedbackContent];    [self.webView stringByEvaluatingJavaScriptFromString:jsStr3];}@end


<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0"/>    <title></title>    <script><!--        window.onload=function(){-->            function setFeedbackTime(timeString){                document.getElementsByClassName('time')[0].innerHTML= timeString;            }            function setUserName(usernameString){                document.getElementsByClassName('username')[0].innerHTML= usernameString;            }            function setFeedbackContent(contentString){                document.getElementsByClassName('content')[0].innerHTML= contentString;            }            document.getElementsByClassName('btn')[0].onclick=function(){                setFeedbackTime("2313123213213");            }<!--        }-->    </script>    <style>        *{            margin: 0;            padding: 0;        }        body{            background-color: white;        }        .mainBox{            width: 100%;            background-color: #feffff;        }        .mainBox  .title{            /*text-indent:2em;*/            margin-left : 10px;            margin-top: 10px;            font-size: 16px;        }        .mainBox .time{            margin-left: 10px;            margin-top: 10px;            height: 20px;            line-height: 20px;            display: block;            overflow: hidden;            color: darkgray;            font-size: 14px;        }        .mainBox .username{            margin-left: 10px;            margin-top: 4px;            height: 20px;            line-height: 20px;            display: block;            overflow: hidden;            color: darkgray;            font-size: 14px;        }        .mainBox .content{            margin-left: 10px;            margin-right: 10px;            margin-top: 10px;            font-size: 14px;        }    </style></head><body><div class="mainBox">    <p class="title">反馈建议</p>    <p class="time">2017-06-24  11:202017-06-24</p>    <p class="username">用户:Nick   联系方式:18253563669</p>    <p class="content">上赛季,尼克-杨在卢克-沃顿的手下状态回暖,他场均得到13.2分,三分命中率为40.4%。从技术特点来说        ,尼克-杨符合勇士队的进攻体系,并且可以成为勇士板凳的得分手。上赛季,尼克-杨在卢克-沃顿的手下状        态回暖,他场均得到13.2分,三分命中率为40.4%。从技术特点来说,尼克-杨符合勇士队的进攻体系,并且        可以成为勇士板凳的得分手。</p><!--    <button class="btn">你好</button>--></div></body></html>


 
原创粉丝点击