2013-01-24 68 views
0

當我嘗試寫入自定義單元格中的標籤時,我遇到了一個問題。所以現在,我有一個名爲「AccountViewController」的表格視圖,並且我有一個自定義單元格「AccountViewCell」的類。我可以讓我的單元格正確顯示在我的表格中,但是當我嘗試在我的自定義單元格眼下鏈接標籤,它們的出口,當我寫標籤創建自定義單元格時寫入標籤Xcode

我的代碼是:

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 

我需要一種能夠寫入標籤的方法。我試過所有我能想到的東西,並閱讀了很多線索,但我無法弄清楚這一點。如果有人可以請求幫助,並且可以讓我給自定義單元格中的標籤寫信,那會很好。

+0

在我看來,你連接到你的AccountViewController而不是你的AccountViewCell。 –

+0

我會怎麼做? –

+0

在NIB編輯器會話中,您的「文件所有者」是..... –

回答

1

好吧,我想通了。我不應該通過文件所有者鏈接標籤,而是通過表格單元格鏈接標籤。

相關問題