2011-02-18 118 views
0

我走過了幾個教程,包括示例應用程序包括 與Three20和想不通爲什麼照片未顯示在我的 TTPhotoViewController起來了。我其實覺得很難調試。 以下是我的代碼。任何想法爲什麼圖像不會加載 以及如何調試它會很好。我在底部的標籤欄和上方的導航欄之間獲得了 的全黑視圖。我也看到左邊和右邊的 箭頭覆蓋在黑色視圖上,似乎是用於導航 照片,儘管我認爲它應該顯示縮略圖 圖庫。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 

回答