我正在使用三个20库进行项目。作为该项目的一部分,我必须在TTThumbsViewController中加载和显示图像。下载图像和设置Photo对象的代码确实已执行,但图像永远不会显示。
However, if I use the same datasource for TTPhotoViewController everything works just fine. I am using 1.0.3 version of the Three20 library. The code of setting up the datasource is
@interface FeedPhotoSource : TTModel <TTPhotoSource> {
NSString* _title;
NSMutableArray* _photosToBeLoaded;
NSMutableArray * _loadedPhotosArray;
}
@property(retain) NSNumber * ownderId;
- (id)initWithTitle:(NSString*)title photos:(NSArray*)photos ownerId:(NSNumber*)ownerId;
@end
///////////////////////////////////////////////////////////////////////////////////////////////////
@interface FeedPhoto : NSObject <TTPhoto> {
id<TTPhotoSource> _photoSource;
NSString* _thumbURL;
NSString* _smallURL;
NSString* _URL;
CGSize _size;
NSInteger _index;
NSString* _caption;
}
- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size;
- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size
caption:(NSString*)caption;
@property(retain, nonatomic) NSString* thumbURL;
@property(retain, nonatomic) NSString* smallURL;
@property(retain, nonatomic) NSString* URL;
@end
实施是
#import "FeedPhotoSource.h"
#import "FacebookGetPhotosRequest.h"
#import "FeedDataRecord.h"
@implementation FeedPhotoSource
@synthesize title = _title;
@synthesize ownderId;
///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
- (id)initWithTitle:(NSString*)title photos:(NSArray*)photos ownerId:(NSNumber*)ownerId
{
if (self = [super init]) {
_title = [title copy];
_photos = photos?[photos mutableCopy] : [[NSMutableArray alloc] init];
self.ownderId = ownerId;
_loadedPhotosArray = [[NSMutableArray alloc] initWithCapacity:4];
_request = nil;
}
return self;
}
- (id)init
{
return [self initWithTitle:nil photos:nil ownerId:nil];
}
- (void)dealloc
{
TT_RELEASE_SAFELY(ownderId);
TT_RELEASE_SAFELY(_photos);
TT_RELEASE_SAFELY(_title);
TT_RELEASE_SAFELY(_loadedPhotosArray);
TT_RELEASE_SAFELY(_request);
[super dealloc];
}
/**
* Indicates that the data has been loaded.
*
* Default implementation returns YES.
*/
- (BOOL)isLoaded
{
int count = [_loadedPhotosArray count] ;
return (count != 0);
}
/**
* Indicates that the data is in the process of loading.
*
* Default implementation returns NO.
*/
- (BOOL)isLoading
{
if (self.isLoaded)
{
return NO;
}
return (_request != nil);
}
- (BOOL)shouldLoadMore
{
return NO;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTModel
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more
{
if (_request != nil)
{
TT_RELEASE_SAFELY(_request);
}
NSMutableArray * _photosArray = [NSMutableArray array];
for(MediaObjectLoadStatus * mediaObjectEntry in _photos)
{
[_photosArray addObject:mediaObjectEntry.photoId];
FeedPhoto * photo = [[[FeedPhoto alloc] initWithURL:mediaObjectEntry.mediaPath smallURL:mediaObjectEntry.mediaPath size:CGSizeMake(320, 480)] autorelease];
photo.pid = mediaObjectEntry.photoId;
[_feedPhotoArray addObject:photo];
}
_request = [[MyRequest alloc] initWithPhotoIds:_photosArray andOwner:ownderId];
_request.delegate = self;
[_request fetchPhotos];
}
/**
* Cancels a load that is in progress.
*
* Default implementation does nothing.
*/
- (void)cancel
{
if (_request != nil)
{
[_request cancelPreviousRequest];
TT_RELEASE_SAFELY(_request);
}
[self didCancelLoad];
}
-(void) Request: (myRequest*)request CompletedSuccessfullyWithResult:(id) result
{
NSMutableArray * resultObj = result;
//Extract and update photosObject
[self didFinishLoad];
}
-(void) Request: (myRequest*)request CompletedWithFailure:(NSError *) error
{
[self didFailLoadWithError:error];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTPhotoSource
- (NSInteger)numberOfPhotos
{
return _photos.count;
}
- (NSInteger)maxPhotoIndex
{
return _photos.count - 1;
}
- (id<TTPhoto>)photoAtIndex:(NSInteger)photoIndex {
if (photoIndex < _feedPhotoArray.count) {
id photo = [_feedPhotoArray objectAtIndex:photoIndex];
if (photo == [NSNull null])
{
return nil;
}
else
{
return photo;
}
}
return nil;
}
@end
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation FeedPhoto
@synthesize photoSource = _photoSource, size = _size, index = _index, caption = _caption;
@synthesize thumbURL = _thumbURL;
@synthesize smallURL = _smallURL;
@synthesize URL = _URL;
///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size {
return [self initWithURL:URL smallURL:smallURL size:size caption:nil];
}
- (id)initWithURL:(NSString*)URL smallURL:(NSString*)smallURL size:(CGSize)size
caption:(NSString*)caption {
if (self = [super init]) {
_photoSource = nil;
_URL = [URL copy];
_smallURL = [smallURL copy];
_thumbURL = [smallURL copy];
_size = size;
_caption = [caption copy];
_index = NSIntegerMax;
}
return self;
}
- (void)dealloc {
TT_RELEASE_SAFELY(_URL);
TT_RELEASE_SAFELY(_smallURL);
TT_RELEASE_SAFELY(_thumbURL);
TT_RELEASE_SAFELY(_caption);
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTPhoto
- (NSString*)URLForVersion:(TTPhotoVersion)version {
if (version == TTPhotoVersionLarge) {
return _URL;
} else if (version == TTPhotoVersionMedium) {
return _URL;
} else if (version == TTPhotoVersionSmall) {
return _smallURL;
} else if (version == TTPhotoVersionThumbnail) {
return _thumbURL;
} else {
return nil;
}
}
@end
答案 0 :(得分:1)
虽然这个问题可能已经解决了,但是对于其他可能会发现这个问题的人来说,这是一个解决方案:
符合TTPhoto协议的对象必须设置其光源。
id<TTPhoto> photo;
photo.photoSource = self;