0

カスタム セルのラベルに書き込もうとすると、問題が発生し続けます。現在、「AccountViewController」というテーブルビューを持つクラスがあり、カスタムセル「AccountViewCell」を持つクラスがあります。セルをテーブルに正しく表示することはできますが、しようとすると問題が発生しますカスタムセルのラベルをアウトレットにリンクし、ラベルに書き込むとき。

現在、私のコードは次のとおりです。

AccountViewController.h

#import <UIKit/UIKit.h>
#import <GameKit/GKSession.h>
#import <GameKit/GKPeerPickerController.h>

@interface AccountViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{

    NSArray     *tableData;
    int         cellValue;
    NSString    *cellContents;

}

@property (nonatomic, retain) NSArray   *tableData;
@property (nonatomic, retain) NSString  *cellContents;
@property (nonatomic, retain) NSString  *accountSelected;
@property (nonatomic, retain) NSString  *accountList;
@property (nonatomic, retain) NSString  *amount;

@end

AccountViewController.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *CellIdentifier = @"AccountViewCell";
    AccountViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        // Load the top-level objects from the custom cell XIB.
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"AccountViewCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        cell = [topLevelObjects objectAtIndex:0];
    }

    // cell.accountNameLabel.text = [tableData objectAtIndex:indexPath.row];

    return cell;

}

AccountViewCell.h:

#import <UIKit/UIKit.h>

@interface AccountViewCell : UITableViewCell


@property (nonatomic, weak) IBOutlet UILabel *accountNameLabel;
@property (nonatomic, weak) IBOutlet UILabel *accountNumberLabel;
@property (nonatomic, weak) IBOutlet UILabel *balanceLabel;

@end

AccountViewCell.m

#import "AccountViewCell.h"

@implementation AccountViewCell

@synthesize accountNameLabel = _accountNameLabel;
@synthesize accountNumberLabel = _accountNumberLabel;
@synthesize balanceLabel = _balanceLabel;

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

    if (self)
    {
        // Initialization code
    }
    return self;
}

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

    // Configure the view for the selected state
}

@end

ここでも、ここに示すように、ラベルのテキストを設定したり、アウトレットを AccountViewCell のラベルに接続したりしないと、コードは正常に動作し、カスタム セルが表示されます。

http://i.imgur.com/TuFun5y.png

私のセル識別子は正しいです: http://i.imgur.com/ZbsDvaa.png

さて、問題は次のようにコンセントを接続するときです: http://imgur.com/OOiKpkM

AccountViewController.m でラベルを設定または宣言しなくても、コードは壊れます。次のエラーが表示されます。

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<AccountViewController 0x104b2220> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accountNameLabel.'
*** First throw call stack:
(0x248e012 0x1d2be7e 0x2516fb1 0x815711 0x796ec8 0x7969b7 0x7c1428 0xd620cc 0x1d3f663 0x248945a 0xd60bcf 0xd6298d 0x28e54 0xbfff4b 0xc0001f 0xbe880b 0xbf919b 0xb9592d 0x1d3f6b0 0x287ffc0 0x287433c 0x2874150 0x27f20bc 0x27f3227 0x27f38e2 0x2456afe 0x2456a3d 0x24347c2 0x2433f44 0x2433e1b 0x29e37e3 0x29e3668 0xb4565c 0x49b2 0x2c45)
libc++abi.dylib: terminate called throwing an exception

ラベルに書き込める方法が必要です。私は考えられるすべてのことを試し、多くのスレッドを読みましたが、これを理解できません。誰かが助けて、カスタムセルのラベルに書き込む方法を教えてくれたら、それは素晴らしいことです.

4

1 に答える 1

1

わかりました、私はそれを理解しました。ファイル所有者を介してラベルをリンクするのではなく、テーブルセルを介してリンクする必要がありました。

于 2013-01-24T20:48:43.457 に答える