2010-09-20 44 views

回答

3

如果你的目標4.0或更高版本可以使用QLPreviewController

包括#import <QuickLook/QuickLook.h>在類

這裏是如何創建一個:

Class qlookclass = NSClassFromString(@"QLPreviewController"); 
     if(qlookclass){ 
      //check if the image exists 
      if([[NSFileManager defaultManager] fileExistsAtPath:@"someimage.png"]){ 
       id quickLookPreview = [[qlookclass alloc]init]; 
       [quickLookPreview setDataSource:self]; 
       [self presentModalViewController:quickLookPreview animated:YES]; 
       [quickLookPreview release]; 
      } 
     } 

然後在你的視圖控制器的其他地方:

#pragma mark QLPreviewController delegate methods 

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller { 
    return 1; 
} 

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index { 

    NSURL *imageURL = [NSURL fileURLWithPath:@"someimage.png"]; 

    return imageURL; 
} 
相關問題