问题
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