我正在尝试通过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
答案 0 :(得分:1)
看起来像是在打电话
[tableView dequeueReusableCellWithIdentifier:@"Photo"];
它正在出现一个UITableViewCell,而不是一个AlbumContentsTableViewCell。由于UITableViewCell没有setRowNumber:选择器,因此它会引发异常。你需要在某处分配和启动你的AlbumContentsTableViewCells。
修改强>
您需要注册AlbumContentsTableViewCell以与@“Photo”标识符一起使用。尝试将此添加到`viewDidLoad'方法:
[self.tableView registerClass:[AlbumContentsTableViewCell class] forCellReuseIdentifier:@"Photo"];
请注意,我还没有测试过这段代码,但我认为它接近你所需要的。