Three20 TTPhotoViewController没有显示照片

时间:2011-02-18 06:47:53

标签: ios three20

我已经完成了一些教程,包括示例应用程序 与Three20并无法弄清楚为什么照片没有出现在我的身上 TTPhotoViewController。我实际上发现很难调试。 以下是我的代码。任何关于图像无法加载的想法 以及如何调试它会很棒。我得到一个完全黑色的视图 在我的底部标签栏和上部导航栏之间。我也看到左右 箭头覆盖在黑色视图上,似乎是用于导航 照片虽然我认为它应该显示缩略图 画廊。

// A TTPhoto class 
// Photo.h 
#import <Foundation/Foundation.h> 
#import <Three20/Three20.h> 
@interface Photo : NSObject <TTPhoto> { 
    NSString *_caption; 
    NSString *_urlLarge; 
    NSString *_urlSmall; 
    NSString *_urlThumb; 
    id <TTPhotoSource> _photoSource; 
    CGSize _size; 
    NSInteger _index; 
} 

@property (nonatomic, copy) NSString *caption; 
@property (nonatomic, copy) NSString *urlLarge; 
@property (nonatomic, copy) NSString *urlSmall; 
@property (nonatomic, copy) NSString *urlThumb; 
@property (nonatomic, assign) id <TTPhotoSource> photoSource; 
@property (nonatomic) CGSize size; 
@property (nonatomic) NSInteger index; 
- (id)initWithCaption:(NSString *)caption urlLarge:(NSString 
*)urlLarge urlSmall:(NSString *)urlSmall urlThumb:(NSString *)urlThumb 
size:(CGSize)size; 
@end 

// Photo.m 
#import "Photo.h" 
@implementation Photo 
@synthesize caption = _caption; 
@synthesize urlLarge = _urlLarge; 
@synthesize urlSmall = _urlSmall; 
@synthesize urlThumb = _urlThumb; 
@synthesize photoSource = _photoSource; 
@synthesize size = _size; 
@synthesize index = _index; 
- (id)initWithCaption:(NSString *)caption urlLarge:(NSString 
*)urlLarge urlSmall:(NSString *)urlSmall urlThumb:(NSString *)urlThumb 
size:(CGSize)size { 
    if ((self = [super init])) { 
        self.caption = caption; 
        self.urlLarge = urlLarge; 
        self.urlSmall = urlSmall; 
        self.urlThumb = urlThumb; 
        self.size = size; 
        self.index = NSIntegerMax; 
        self.photoSource = nil; 
    } 
    return self; 
} 

- (void) dealloc { 
    self.caption = nil; 
    self.urlLarge = nil; 
    self.urlSmall = nil; 
    self.urlThumb = nil; 
    [super dealloc]; 
} 

#pragma mark TTPhoto 
- (NSString*)URLForVersion:(TTPhotoVersion)version { 
    switch (version) { 
        case TTPhotoVersionLarge: 
            return _urlLarge; 
        case TTPhotoVersionMedium: 
            return _urlLarge; 
        case TTPhotoVersionSmall: 
            return _urlSmall; 
        case TTPhotoVersionThumbnail: 
            return _urlThumb; 
        default: 
            return nil; 
    } 
} 

@end 

// A TTPhotoSource class 
// PhotoSet.h 
#import <Foundation/Foundation.h> 
#import "Three20/Three20.h" 
@interface PhotoSet : TTURLRequestModel <TTPhotoSource> { 
    NSString *_title; 
    NSArray *_photos; 
        NSArray* _tempPhotos; 
        NSTimer* _fakeLoadTimer; 
} 

@property (nonatomic, copy) NSString *title; 
@property (nonatomic, retain) NSArray *photos; 
- (id) init; 
@end 

// PhotoSet.m 
#import "PhotoSet.h" 
#import "Photo.h" 
@implementation PhotoSet 
@synthesize title = _title; 
@synthesize photos = _photos; 
- (id) init { 
        _title = @"Test photo album"; 
        _photos = [[NSArray alloc] initWithObjects: 
                           [[[Photo alloc] initWithCaption:@"coming soon" 
                                                                          urlLarge:@"http://farm5.static.flickr.com/ 
4066/4653156849_0905e6b58e_o.jpg" 
                                                                          urlSmall:@"http://farm5.static.flickr.com/ 
4066/4653156849_0d15f0e3f0_s.jpg" 
                                                                          urlThumb:@"http://farm5.static.flickr.com/ 
4066/4653156849_0d15f0e3f0_s.jpg" 
                                                                                  size:CGSizeMake(220, 112)] autorelease], 
                           [[[Photo alloc] initWithCaption:@"coming soon 2" 
                                                                          urlLarge:@"http://farm5.static.flickr.com/ 
4023/4653774402_05e6acd995_o.jpg" 
                                                                          urlSmall:@"http://farm5.static.flickr.com/ 
4009/4653157237_c2f5f59e0d_s.jpg" 
                                                                          urlThumb:@"http://farm5.static.flickr.com/ 
4009/4653157237_c2f5f59e0d_s.jpg" 
                                                                                  size:CGSizeMake(220, 112)] autorelease], 
                           [[[Photo alloc] initWithCaption:@"coming soon 2" 
                                                                          urlLarge:@"http://farm5.static.flickr.com/ 
4023/4653774402_05e6acd995_o.jpg" 
                                                                          urlSmall:@"http://farm5.static.flickr.com/ 
4009/4653157237_c2f5f59e0d_s.jpg" 
                                                                          urlThumb:@"http://farm5.static.flickr.com/ 
4009/4653157237_c2f5f59e0d_s.jpg" 
                                                                                  size:CGSizeMake(220, 112)] autorelease], 
                           [[[Photo alloc] initWithCaption:@"coming soon 2" 
                                                                          urlLarge:@"http://farm5.static.flickr.com/ 
4023/4653774402_05e6acd995_o.jpg" 
                                                                          urlSmall:@"http://farm5.static.flickr.com/ 
4009/4653157237_c2f5f59e0d_s.jpg" 
                                                                          urlThumb:@"http://farm5.static.flickr.com/ 
4009/4653157237_c2f5f59e0d_s.jpg" 
                                                                                  size:CGSizeMake(220, 112)] autorelease], 
                           nil]; 
        for (int i = 0; i < _photos.count; ++i) { 
                id<TTPhoto> photo = [_photos objectAtIndex:i]; 
                if ((NSNull*)photo != [NSNull null]) { 
                        NSLog(@"in here 65434"); 
                        photo.photoSource = self; 
                        photo.index = i; 
                } 
    } 
    return self; 
} 

- (void) dealloc { 
    self.title = nil; 
    self.photos = nil; 
    [super dealloc]; 
} 

#pragma mark TTModel 
- (BOOL)isLoading { 
        return NO; 
} 

- (BOOL)isLoaded { 
    return YES; 
} 

#pragma mark TTPhotoSource 
- (NSInteger)numberOfPhotos { 
    return _photos.count; 
} 

- (NSInteger)maxPhotoIndex { 
    return _photos.count-1; 
} 

- (id<TTPhoto>)photoAtIndex:(NSInteger)photoIndex { 
    if (photoIndex < _photos.count) { 
        return [_photos objectAtIndex:photoIndex]; 
    } else { 
        return nil; 
    } 
} 

@end 

// A TTPhotoViewController 
// EventDetailViewController.h 
#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 
#import <Three20/Three20.h> 
#import "PhotoSet.h" 
@class Event; 
@interface EventDetailViewController : 
TTPhotoViewController<UINavigationControllerDelegate, 
UIImagePickerControllerDelegate> { 
        NSArray *photos; 
        Event *event; 
        PhotoSet *_photoSet; 
} 

@property (nonatomic, retain) NSArray *photos; 
@property (nonatomic, retain) Event *event; 
@property (nonatomic, retain) PhotoSet *photoSet; 
- (id)initWithEvent:(Event *)e; 

// EventDetailViewController.m 
#import "EventDetailViewController.h" 
#import "Event.h" 
#import "PhotoSet.h" 
#import "Photo.h" 
@implementation EventDetailViewController 
@synthesize photos; 
@synthesize event; 
@synthesize photoSet = _photoSet; 
#pragma mark - 
#pragma mark Initialization 
- (void)viewDidLoad { 
        self.photoSet = [[PhotoSet alloc] init]; 
        self.photoSource = self.photoSet; 
} 

- (id)initWithEvent:(Event *)e { 
    if (self) { 
        self.event = e; 
    } 
    return self; 
} 

@end

1 个答案:

答案 0 :(得分:1)