6

カスタム テーブル セルを実装しましたが、テーブルが cellForRowAtIndexPath に入ると、実行時エラー (「インスタンスに認識されないセレクターが送信されました」) が発生します。カスタム セルをインスタンス化しようとすると、エラーが発生します。以前はこれを成功させましたが、今ではエラーは消えません。プロトタイプ セルがあり、そのカスタム クラス属性がカスタム セル UITableViewCell サブクラスに設定されています。カスタムセルは次のとおりです。

#import "FavoriteCell.h"

@implementation FavoriteCell
@synthesize lblGaugeID, lblMainTitle, bgImage;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    bgImage = [UIImage imageNamed:@"tableCellBG.png"];
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIColor *transparentBG = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
        UIColor *foregroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
        //UIColor *shadowColot = [UIColor colorWithWhite:0.75 alpha:1.0];

        CGSize size = self.contentView.frame.size;
        self.backgroundView = [[UIImageView alloc] initWithImage:bgImage];
        self.lblMainTitle = [[UILabel alloc] initWithFrame:CGRectMake(8.0, 0.5, size.width-16, size.height-40)];
        [self.lblMainTitle setFont:[UIFont systemFontOfSize:12.0]];
        [self.lblMainTitle setTextAlignment:NSTextAlignmentLeft];
        [self.lblMainTitle setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
        [self.lblMainTitle setBackgroundColor:transparentBG];

        self.lblGaugeID = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 31.0, size.width-16, size.height-40)];
        [self.lblGaugeID setFont:[UIFont boldSystemFontOfSize:15.0]];
        [self.lblGaugeID setTextAlignment:NSTextAlignmentLeft];
        [self.lblGaugeID setTextColor:foregroundColor];
        [self.lblGaugeID setShadowOffset:CGSizeMake(0.2 , 0.2)];
        [self.lblGaugeID setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
        [self.lblGaugeID setBackgroundColor:transparentBG];

        [self.contentView addSubview:lblGaugeID];
        [self.contentView addSubview:lblMainTitle];
    }
    return self;
}

@end

そして、これがインスタンス化された場所です(私のView Controllerクラスから抜粋):

-(FavoriteCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"favoriteCell";
    FavoriteCell *cell = (FavoriteCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; //error
    if(cell == nil){
        cell = [[FavoriteCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    NSString *siteName = [faveKeys objectAtIndex:indexPath.row];

    [cell.lblMainTitle setText:siteName];
    [cell.lblGaugeID setText:[allFavorites objectForKey:siteName]];
    return cell;
}

完全なエラー メッセージは次のとおりです。

*キャッチされていない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。

誰が何をチェックするべきかについてアドバイスを提供できますか? ありがとう!ビビアン

4

1 に答える 1