QLPreviewController - setting previewItemTitle

时光总嘲笑我的痴心妄想 提交于 2019-12-07 11:24:20

问题


I can't work out how to set the previewItemTitle property for my QLPreviewController class. Its seems a bit strange as the iPhone developer document for this class says that that property is @property (readonly) which would mean that I cannot set it.

Any ideas. Thanks

My code:

QLPreviewController *preview = [[QLPreviewController alloc] init];
    [preview setDataSource:self];

    [self presentModalViewController:preview animated:YES];

回答1:


QLPreviewController has no previewItemTitle property. You mean the QLPreviewItem protocol.

"Readonly" means that you can't set it via the property (unless it's overridden); i.e. the property does not declare a setPreviewItemTitle: method. This makes sense for the protocol: the controller does not expect to be able to set the preview item titles.

For the most basic preview item, you could use something like this:

@interface BasicPreviewItem : NSObject<QLPreviewItem>
{
}

@property (nonatomic, retain) NSURL * previewItemURL;
@property (nonatomic, copy) NSString* previewItemTitle;

@end

@implementation BasicPreviewItem

@synthesize previewItemURL, previewItemTitle;

-(void)dealloc
{
  self.previewItemURL = nil;
  self.previewItemTitle = nil;
  [super dealloc];
}

@end

However, the point of the protocol is so that you can take any class and add -(NSURL*)previewItemURL and -(NSString*)previewItemTitle methods (e.g. if you had a music player, you could add those methods to the "Track" class and be able to preview tracks).



来源:https://stackoverflow.com/questions/3790014/qlpreviewcontroller-setting-previewitemtitle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!