tableView 去掉多余的行数 && iOS 中直接用WebView 加载pdf doc docx 等文件

来源:互联网 发布:linux 服务器鸟哥 编辑:程序博客网 时间:2024/06/05 04:44

//去掉底部多余的表格线[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];//最后一行分隔线顶头显示static void setLastCellSeperatorToLeft(UITableViewCell* cell){    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {        [cell setSeparatorInset:UIEdgeInsetsZero];    }        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {        [cell setLayoutMargins:UIEdgeInsetsZero];    }        if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]){        [cell setPreservesSuperviewLayoutMargins:NO];    }}

 iOS 中直接用WebView 加载pdf doc docx 等文件

-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView{    NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:@"docx"];    NSURL *url = [NSURL fileURLWithPath:path];    NSURLRequest *request = [NSURLRequest requestWithURL:url];    [webView loadRequest:request];}//调用去加载[self loadDocument:@"aaa" inView:self.MyWeb];

通过 self.webview.scalesPageToFit = YES;  //会自动根据内容适应屏幕

WebView 加载网页、PDF、doc、视频等都可以加载,

可以自动检测网页中的电话和链接:

self.webview.dataDetectorTypes = UIDataDetectorTypeAll; 就可以在网页上直接显示链接和电话号码,真机上可以直接用来发邮件和打电话。

1. OC调用网页中的js方法

  1. 加载网页

    NSURL *url = [[NSBundle mainBundleURLForResource:@"index.html" withExtension:nil];NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [self.webView loadRequest:request];

  2. webView加载完成后执行js的方法

  3. 设置webView的代理

  4. 代理方法,当网页加载完毕执行js方法
    - (void)webViewDidFinishLoad:(UIWebView *)webView{

    [self.webView stringByEvaluatingJavaScriptFromString:@"game.chessboard.drawPlanes()"];}

  5. 获取js方法的返回值
    NSString *str= [self.webView stringByEvaluatingJavaScriptFromString:@"test()"];

2. 网页中调用OC的方法a. 获取URL中的信息

NSLog(@"%@",request.URL.scheme); //协议NSLog(@"%@",request.URL.relativePath); //相对路径NSLog(@"%@",request.URL.absoluteURL); //绝对路径NSLog(@"%@",request.URL.pathComponents); //获取url中的每一部分NSLog(@"%@",request.URL.lastPathComponent); //获取url中的最后一部分

b. 代码

//判断协议头是否是自定义协议头如果是的话。加载自定义方法if (![request.URL.scheme isEqualToString:@"itcast"]) {

return YES;}

//获取自定义url中的方法
NSString *methodName = request.URL.pathComponents[1];//获取url上的参数
NSString *param = request.URL.pathComponents[2];

//把方法名称转换成selector
SEL sel = NSSelectorFromString(methodName);if ([self respondsToSelector:sel]) {

//忽略警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored 
"-Warc-performSelector-leaks"

//执行方法

[self performSelector:sel withObject:param];#pragma mark diagnostic pop





0 0
原创粉丝点击