开发者

TTThumbsViewController not displaying images

开发者 https://www.devze.com 2023-02-10 10:40 出处:网络
Iam working on a project using the three 20 library. As part of this project I have to load and display the images in TTThumbsViewController. The code to download images and setup a Photo object does

I am working on a project using the three 20 library. As part of this project I have to load and display the images in TTThumbsViewController. The code to download images and setup a Photo object does get executed but the images are never displayed.

TTThumbsViewController not displaying images

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;
    N开发者_JAVA百科SMutableArray * _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

And the implementation is

#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


Although, this question has probably already been solved, here is the solution for others who may find this question:

Your object that conforms to the TTPhoto protocol must have its photosource set.

id<TTPhoto> photo;
photo.photoSource = self;
0

精彩评论

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