2010-08-07 3 views
0

я могу загрузить веб-просмотра на кнопку печати, как этотвеб-страницы загружаются образуют массив для Iphone

-(void)buttonEvent:(UIButton*)sender{ 
     NSLog(@"new button clicked!!!"); 
    if (sender.tag == 1) { 




     NSLog(@"1"); 
    } 
    if (sender.tag == 2) { 
     NSLog(@"2"); 

     NSString *path; 
     NSBundle *thisBundle = [NSBundle mainBundle]; 


     path = [thisBundle pathForResource:@"index2" ofType:@"html"]; 




     NSURL *instructionsURL = [[NSURL alloc] initFileURLWithPath:path]; 
     [webView loadRequest:[NSURLRequest requestWithURL:instructionsURL]]; 



    } 
} 

, но я хочу, чтобы загрузить значение пути из моей строки NSString *filepat=[listItems objectAtIndex:2]; , значение которого TAB0/index1.html где TAB0 папка

так, как загрузить из этой строки плз помочь

Благодарности

ответ

2
// get the app's base directory 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 
// get the dir/filename 
NSString *filepat=[listItems objectAtIndex:2]; 
// concatenate for full path 
NSString *filePath = [basePath stringByAppendingString:filepat]; 
NSURL *instructionsURL = [[NSURL alloc] initFileURLWithPath:filePath]; 
[webView loadRequest:[NSURLRequest requestWithURL:instructionsURL]]; 

Вы также можете использовать кеш, как я использую - SimpleDiskCache.m - который будет извлекать URL-адреса из Интернета и кэшировать и извлекать их с диска.

// SimpleDiskCache.h 

@interface SimpleDiskCache : NSObject { } 

+ (void) cacheURL:(NSURL*) url forData:(NSData*)data; 
+ (NSData*) getDataForURL:(NSURL*) url; 

@end 


// SimpleDiskCache.m 

#import "SimpleDiskCache.h" 
#import "util.h" 

@implementation SimpleDiskCache 


+ (NSCharacterSet*) getNonAlphaNumericCharacterSet { 
    static NSCharacterSet* cs; 
    if (!cs) { 
    cs = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; 
    cs = [cs retain]; 
    } 
    return cs; 
} 

+ (void) cacheURL:(NSURL*) url forData:(NSData*)data { 
    NSString* filename = [[[url absoluteString] componentsSeparatedByCharactersInSet: 
         [NSCharacterSet punctuationCharacterSet]] componentsJoinedByString:@""]; 
    NSString * storePath = [NSTemporaryDirectory() stringByAppendingPathComponent:filename]; 
    [data writeToFile:storePath atomically:NO]; 
} 


+ (NSData*) getDataForURL:(NSURL*) url { 
    NSString* filename = [[[url absoluteString] componentsSeparatedByCharactersInSet: 
         [NSCharacterSet punctuationCharacterSet]] componentsJoinedByString:@""]; 
    NSString * storePath = [NSTemporaryDirectory() stringByAppendingPathComponent:filename]; 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    if ([fileManager fileExistsAtPath:storePath]) { 
    return [NSData dataWithContentsOfFile:storePath]; 
    } 
    return nil; 
} 

@end 
Смежные вопросы