我正在尝试通过 ALAssets 库构建我的图像选择器,并且我有一个包含相册的表格视图,但是当我单击相册查看照片时,在由自定义 UITableViewCells 组成的动态 UITableViewController 中,它不允许我将属性分配给我的自定义 AlbumContentTableViewCells...
cell.rowNumber 和 indexPath.row 都是 NSIntegers 但它抱怨一个无法识别的选择器......
// 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;
}
当我尝试将此自定义 UITableCell 分配其“rowNumber”属性时出现此错误:
'NSInvalidArgumentException',原因:'-[UITableViewCell setRowNumber:]:无法识别的选择器发送到实例 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