开发者

QLPreviewController - setting previewItemTitle

开发者 https://www.devze.com 2023-01-17 17:19 出处:网络
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 @propert

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];
开发者_JS百科


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消