Reputation: 2102
I am trying to build my image picker through the ALAssets library and I have a table view with the albums but when i click on the album to view the photos, in a dynamic UITableViewController composed of custom UITableViewCells it doesnt allow me to assign properties to my custom AlbumContentTableViewCells...
Both cell.rowNumber & indexPath.row are NSIntegers but its complaining about an unrecognized selector...
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
AlbumContentsTableViewCell *cell = [[AlbumContentsTableViewCell alloc] init];
cell = (AlbumContentsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"Photo"];
cell.rowNumber = indexPath.row;
cell.selectionDelegate = self;
// Configure the cell...
NSUInteger firstPhotoInCell = indexPath.row * 4;
NSUInteger lastPhotoInCell = firstPhotoInCell + 4;
if (assets.count <= firstPhotoInCell) {
NSLog(@"We are out of range, asking to start with photo %d but we only have %d", firstPhotoInCell, assets.count);
return nil;
}
NSUInteger currentPhotoIndex = 0;
NSUInteger lastPhotoIndex = MIN(lastPhotoInCell, assets.count);
for ( ; firstPhotoInCell + currentPhotoIndex < lastPhotoIndex ; currentPhotoIndex++) {
ALAsset *asset = [assets objectAtIndex:firstPhotoInCell + currentPhotoIndex];
CGImageRef thumbnailImageRef = [asset thumbnail];
UIImage *thumbnail = [UIImage imageWithCGImage:thumbnailImageRef];
switch (currentPhotoIndex) {
case 0:
[cell photo1].image = thumbnail;
break;
case 1:
[cell photo2].image = thumbnail;
break;
case 2:
[cell photo3].image = thumbnail;
break;
case 3:
[cell photo4].image = thumbnail;
break;
default:
break;
}
}
return cell;
}
I get this error when I try to assign this custom UITableCell its 'rowNumber' property:
'NSInvalidArgumentException', reason: '-[UITableViewCell setRowNumber:]: unrecognized selector sent to instance 0x1e2a43a0'
AlbumContentsTableViewCell.h
#import <UIKit/UIKit.h>
#import "ThumbnailImageView.h"
@class AlbumContentsTableViewCell;
@protocol AlbumContentsTableViewCellSelectionDelegate <NSObject>
- (void)albumContentsTableViewCell:(AlbumContentsTableViewCell *)cell selectedPhotoAtIndex:(NSUInteger)index;
@end
@interface AlbumContentsTableViewCell : UITableViewCell <ThumbnailImageViewSelectionDelegate> {
IBOutlet ThumbnailImageView *photo1;
IBOutlet ThumbnailImageView *photo2;
IBOutlet ThumbnailImageView *photo3;
IBOutlet ThumbnailImageView *photo4;
NSInteger rowNumber;
//id <AlbumContentsTableViewCellSelectionDelegate> selectionDelegate;
}
@property (nonatomic) NSInteger rowNumber;
@property (nonatomic, weak) id<AlbumContentsTableViewCellSelectionDelegate> selectionDelegate;
- (UIImageView *)photo1;
- (UIImageView *)photo2;
- (UIImageView *)photo3;
- (UIImageView *)photo4;
- (void)clearSelection;
@end
AlbumContentsTableViewCell.m
#import "AlbumContentsTableViewCell.h"
#import "ThumbnailImageView.h"
@implementation AlbumContentsTableViewCell
@synthesize rowNumber;
@synthesize selectionDelegate;
#import <UIKit/UIKit.h>
@class ThumbnailImageView;
@protocol ThumbnailImageViewSelectionDelegate <NSObject>
- (void)thumbnailImageViewWasSelected:(ThumbnailImageView *)thumbnailImageView;
@end
@interface ThumbnailImageView : UIImageView {
UIImageView *highlightView;
id <ThumbnailImageViewSelectionDelegate> delegate;
}
@property(nonatomic, assign) id<ThumbnailImageViewSelectionDelegate> delegate;
- (void)clearSelection;
@end
Upvotes: 0
Views: 218
Reputation: 1127
It looks like when you are calling
[tableView dequeueReusableCellWithIdentifier:@"Photo"];
It is dequeuing a UITableViewCell and not an AlbumContentsTableViewCell. Since UITableViewCell does not have a setRowNumber: selector it is throwing an exception. You need to be allocating and initing your AlbumContentsTableViewCells somewhere.
EDIT:
You need to register your AlbumContentsTableViewCell for use with your @"Photo" identifier. Try adding this to your `viewDidLoad' method:
[self.tableView registerClass:[AlbumContentsTableViewCell class] forCellReuseIdentifier:@"Photo"];
Note that I haven't tested this code out, but I think it is close to what you need.
Upvotes: 1