0

グループ化されたスタイルで使用するカスタム セルを作成しようとしていますUITableView。ただし、コードを実行すると、コードでマークされたポイントでエラーが発生し続けます。私は何が間違っているのか分かりません。誰か助けてくれませんか?

.h ファイル:

@interface CustomRecommendedStepCell : UITableViewCell
{
    UILabel *stepNumber;
    UITextView *stepInstruction;
}


@property(nonatomic, retain)IBOutlet UILabel *stepNumber;
@property(nonatomic, retain)IBOutlet UITextView *stepInstruction;


@end

.m ファイル:

#import "CustomRecommendedStepCell.h"

@implementation CustomRecommendedStepCell
@synthesize stepNumber, stepInstruction;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self)
    {
        UIImageView *backgroundView = [[UIImageView alloc] init];
        [backgroundView setImage:[UIImage imageNamed:@"Slate_bg.png"]];
        self.backgroundView = backgroundView;
        self.backgroundColor = [UIColor clearColor];

        stepNumber = [[UILabel alloc] init];
        stepNumber.textAlignment = UITextAlignmentLeft;
        stepNumber.font = [UIFont fontWithName:kCustomFont1 size:40];
        stepNumber.textColor =[UIColor whiteColor];
        stepNumber.backgroundColor = [UIColor clearColor];

        stepInstruction = [[UITextView alloc] init];
        stepInstruction.editable = NO;
        stepInstruction.textAlignment = UITextAlignmentLeft;
        stepInstruction.font = [UIFont fontWithName:kCustomFont1 size:23];
        stepInstruction.textColor =[UIColor whiteColor];
        stepInstruction.backgroundColor = [UIColor clearColor];

        [self.contentView addSubview:stepNumber];
        [self.contentView addSubview:stepInstruction];
    }

    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];

    stepNumber.frame = CGRectMake(20, 20, 50, 60);        // PROBLEM OCCURS HERE!
    stepInstruction.frame = CGRectMake(70, 20, 200, 60);
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

受信したログ メッセージのコピーを次に示します。

2011-12-22 20:34:09.801 一部のアプリ [30945:10703] -[__NSCFString setFrame:]: インスタンス 0x756b340 に送信された認識されないセレクター
2011-12-22 20:34:09.802 一部のアプリ [30945:10703] *** キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。理由: '-[__NSCFString setFrame:]: 認識されないセレクターがインスタンス 0x756b340 に送信されました'
*** 最初のスロー コール スタック:
(0x11f052 0x1845d0a 0x120ced 0x85f00 0x85ce2 0xd7c1 0x778322 0x120e72 0x359792d 0x35a1827 0x35a1922 0x771f47 0x924edd 0x7d2fe1 0x7d3589 0x7bedfd 0x7cd851 0x778301 0x120e72 0x359792d 0x35a1827 0x3527fa7 0x3529ea6 0x3529580 0xf39ce 0x8a670 0x564f6 0x55db4 0x55ccb 0x3ab4879 0x3ab493e 0x739a9b 0x2128 0x2085 0x1)
例外をスローして呼び出された終了
4

3 に答える 3

2

あなたのtableView:cellForRowAtIndexPath:方法では、次のようなことをしているようです

cell.stepNumber = @"text";

それ以外の

cell.stepNumber.text = @"text";
于 2011-12-22T20:45:57.820 に答える
1

私は問題がこのコードにあるとは思わない.. tableView:cellForRowAtIndexPath:Eugeneが提案したようにあなたの方法をチェックしてください。NSStringの代わりにUITableViewCell?を返しているのではないかと思います。

于 2011-12-22T20:52:45.090 に答える
0

呼び出された時点layoutSubviewsで、あなたのstepNumberレーベルはすでにリリースされている (または割り当てられていない) ようです。

カスタムセルをインスタンス化する方法を確認する必要があると思います。initWithStyle: メソッドが呼び出されていると確信していますか?

cellForRowAtIndexPath:ビューコントローラーのメソッドを投稿できますか?

于 2011-12-22T20:49:09.163 に答える