To continue where we left off
In MyAlbumViewController didSelectRowAtIndexPath you want to do something like this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
userDataConnection = [[UserDataConnection alloc] initWithDelegate:self];
NSLog(@"this is the row in the table view %u", indexPath.row);
NSDictionary* album = [myAlbums objectAtIndex:indexPath.row];
[userDataConnection getUserDataWithAid:[album objectForKey:@"aid"]];
}
/**
Handle deletion of an event.
*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
}
}
In the did select role do something like this
- (void)userAlbumArtConnection:(UserAlbumArtConnection *)userAlbumArtConnection indexPath:(NSIndexPath *)index receivedList:(NSArray*)receivedList
{
NSLog(@"did get art pic data");
NSLog(@"get art row and index %u", index.row);
NSLog(@"receivedList count %u", [receivedList count]);
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:index];
// for (NSDictionary *photosDictionary in receivedList) {
// NSString *cover = [photosDictionary objectForKey:@"src_small"];
// NSLog(@"Query returned src %@", cover);
// }
if ([receivedList count] !=0 ) {
NSDictionary *photosDictionary = [receivedList objectAtIndex:0];
NSString *src = [photosDictionary objectForKey:@"src_small"];
NSURL *fcURL = [NSURL URLWithString:src];
NSData *fcData = [NSData dataWithContentsOfURL:fcURL];
UIImage *image = [[UIImage alloc] initWithData:fcData];
CGRect rect = CGRectMake(0.0, 0.0, 50, 50);
UIGraphicsBeginImageContext(rect.size);
[image drawInRect:rect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
//cell.detailTextLabel.text = src;
UIGraphicsEndImageContext();
}
}
- (void) userPhotoConnection:(UserPhotoConnection *)userPhotoConnection receivedList:(NSArray*)receivedList {
NSLog(@"did get photo data");
NSLog(@"receivedList count %u", [receivedList count]);
FcPhotoController *browser = [FcPhotoController alloc] ;
[browser initWithArray:receivedList];
[self.navigationController pushViewController:browser
animatedWithTransition:UIViewAnimationTransitionCurlDown];
[browser release];
}
FCPhotoController is somewhat a copy of photoTest2
#import "FcPhotoController.h" #import "TTThumbsViewController.h" #import "TTPhotoSource.h" #import "FcPhotoSource.h" #import "MyAlbumsViewController.h" @implementation FcPhotoController - (void) initWithArray:(NSArray*)photoData { self.photoSource = [[FcPhotoSource alloc] initWithType:FcPhotoSourceNormal title:@"Public Photos" data:photoData photos2:nil ]; } -(id) initWithTabBar { if ([self init]) { //this is the label on the tab button itself self.title = @"browse"; // set the long name shown in the navigation bar self.navigationItem.title=@"browse"; } return self; } @end And this is FcPhotoSource #import "TTDefaultStyleSheet.h" #import "FcPhotoSource.h" #import "TTPhotoSource.h" @implementation FcPhotoSource @synthesize title = _title; /////////////////////////////////////////////////////////////////////////////////////////////////// // private - (void)fakeLoadReady { _fakeLoadTimer = nil; if (_type & FcPhotoSourceLoadError) { [_delegates perform:@selector(model:didFailLoadWithError:) withObject:self withObject:nil]; } else { NSMutableArray* newPhotos = [NSMutableArray array]; for (int i = 0; i < _photos.count; ++i) { id<TTPhoto> photo = [_photos objectAtIndex:i]; if ((NSNull*)photo != [NSNull null]) { [newPhotos addObject:photo]; } } [newPhotos addObjectsFromArray:_tempPhotos]; TT_RELEASE_SAFELY(_tempPhotos); [_photos release]; _photos = [newPhotos retain]; for (int i = 0; i < _photos.count; ++i) { id<TTPhoto> photo = [_photos objectAtIndex:i]; if ((NSNull*)photo != [NSNull null]) { photo.photoSource = self; photo.index = i; } } [_delegates perform:@selector(modelDidFinishLoad:) withObject:self]; } } - (void)handleError:(NSError *)error { NSLog(@"An error occurred in fcPhoto"); } /////////////////////////////////////////////////////////////////////////////////////////////////// // NSObject - (id)initWithType:(FcPhotoSourceType)type title:(NSString*)title data:(NSArray*)photoData photos2:(NSArray*)photos2 { photosFromWeb = [[NSMutableArray alloc] init]; for (NSDictionary *photosDictionary in photoData) { [photosFromWeb addObject: [[[FcPhoto alloc] initWithURL:[photosDictionary objectForKey:@"src_big"] smallURL:[photosDictionary objectForKey:@"src_small"] size:CGSizeMake(604, 604) caption:@"Photo from facebook"] autorelease]]; } NSArray *photos = [NSArray arrayWithArray:photosFromWeb]; if (self = [super init]) { _type = type; _title = [title copy]; _photos = photos2 ? [photos mutableCopy] : [[NSMutableArray alloc] init]; _tempPhotos = photos2 ? [photos2 retain] : [photos retain]; _fakeLoadTimer = nil; for (int i = 0; i < _photos.count; ++i) { id<TTPhoto> photo = [_photos objectAtIndex:i]; if ((NSNull*)photo != [NSNull null]) { photo.photoSource = self; photo.index = i; } } if (!(_type & FcPhotoSourceDelayed || photos2)) { [self performSelector:@selector(fakeLoadReady)]; } } return self; } - (id)init { return [self initWithType:FcPhotoSourceNormal title:nil data:nil photos2:nil]; } - (void)dealloc { [_fakeLoadTimer invalidate]; TT_RELEASE_SAFELY(_photos); TT_RELEASE_SAFELY(_tempPhotos); TT_RELEASE_SAFELY(_title); [super dealloc]; } /////////////////////////////////////////////////////////////////////////////////////////////////// // TTModel - (BOOL)isLoading { return !!_fakeLoadTimer; } - (BOOL)isLoaded { return !!_photos; } - (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more { if (cachePolicy & TTURLRequestCachePolicyNetwork) { [_delegates perform:@selector(modelDidStartLoad:) withObject:self]; TT_RELEASE_SAFELY(_photos); _fakeLoadTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(fakeLoadReady) userInfo:nil repeats:NO]; } } - (void)cancel { [_fakeLoadTimer invalidate]; _fakeLoadTimer = nil; } /////////////////////////////////////////////////////////////////////////////////////////////////// // TTPhotoSource - (NSInteger)numberOfPhotos { if (_tempPhotos) { return _photos.count + (_type & FcPhotoSourceVariableCount ? 0 : _tempPhotos.count); } else { return _photos.count; } } - (NSInteger)maxPhotoIndex { return _photos.count-1; } - (id<TTPhoto>)photoAtIndex:(NSInteger)index { if (index < _photos.count) { id photo = [_photos objectAtIndex:index]; if (photo == [NSNull null]) { return nil; } else { return photo; } } else { return nil; } } @end /////////////////////////////////////////////////////////////////////////////////////////////////// @implementation FcPhoto @synthesize photoSource = _photoSource, size = _size, index = _index, caption = _caption; /////////////////////////////////////////////////////////////////////////////////////////////////// // 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
Comments