Ios file doc.txt and so on

Source: Internet
Author: User

1. uidocumentinteractioncontroller full screen display

#import <Foundation/Foundation.h>@interface LLFileVC : UIViewController<UIDocumentInteractionControllerDelegate>{        BOOL        _isShowing;    NSURL    *_docURL;}@property (nonatomic, retain) UIDocumentInteractionController *docInteractionController;-(id)initWithURL:(NSURL*)aURL;@end

#import "LLFileVC.h"@implementation LLFileVC@synthesize docInteractionController;-(id)initWithURL:(NSURL *)aURL{    if (self=[super init]) {        _isShowing = NO;        _docURL = [aURL retain];    }    return self;}-(void)dealloc{        [docInteractionController release];    [_docURL release];        [super dealloc];}-(void)showFile{    if (_docURL) {        self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:_docURL];        self.docInteractionController.delegate = self;        if (![self.docInteractionController presentPreviewAnimated:YES]){        }            }}-(void)viewDidAppear:(BOOL)animated{    if (!_isShowing) {        [self showFile];    }else{        [self dismissModalViewControllerAnimated:NO];    }    [super viewDidAppear:animated];}#pragma mark -#pragma mark UIDocumentInteractionControllerDelegate- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{    return self;}- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{    return self.view;}- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller canPerformAction:(SEL)action{    BOOL canPerform = NO;    if (action == @selector(copy:))        canPerform = YES;    return canPerform;}- (BOOL)documentInteractionController:(UIDocumentInteractionController *)controller performAction:(SEL)action{    BOOL handled = NO;    if (action == @selector(copy:)){        handled = YES;    }    return handled;}- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController*)controller{return self.view.frame;}- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller{    _isShowing = YES;}- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation == UIInterfaceOrientationLandscapeRight) {return YES;}else {return NO;}}@end

// Call full screen browsing

NSString *rootPath = [self getDocumentsPath];            NSString *filePath = [NSString stringWithFormat:@"%@/doc/%@",rootPath,_downLoadName];            LLFileVC *aLLFileVC = [[[LLFileVC alloc] initWithURL:[NSURL fileURLWithPath:filePath]] autorelease];            AppDelegate *app  = (AppDelegate*)[UIApplication sharedApplication].delegate;            [app.window.rootViewController presentModalViewController:aLLFileVC animated:NO];

Ii. uiwebview display partial view

if (!_webView) {        _webView = [[UIWebView alloc] initWithFrame:_contentView.bounds];        _webView.scalesPageToFit = YES;        [_contentView addSubview:_webView];    }        NSString *rootPath = [self getDocumentsPath];    NSString *filePath = [NSString stringWithFormat:@"%@/weekdoc/%@",rootPath,[NSString stringWithFormat:@"%@",[aDic objectForKey:@"wjm"]]];    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]];    [_webView loadRequest:request];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.