0

我正在尝试通过 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
4

1 回答 1

1

看起来像你打电话的时候

[tableView dequeueReusableCellWithIdentifier:@"Photo"];

它使 UITableViewCell 而不是 AlbumContentsTableViewCell 出队。由于 UITableViewCell 没有 setRowNumber: 选择器,因此它会引发异常。您需要在某处分配和初始化您的 AlbumContentsTableViewCells。

编辑:
您需要注册您的 AlbumContentsTableViewCell 以与您的 @"Photo" 标识符一起使用。尝试将此添加到您的 `viewDidLoad' 方法中:

    [self.tableView registerClass:[AlbumContentsTableViewCell class] forCellReuseIdentifier:@"Photo"];

请注意,我尚未测试此代码,但我认为它接近您的需要。

于 2013-07-24T01:38:04.330 回答