2013-01-24 34 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

好吧,我想通了。我不应该通过文件所有者链接标签,而是通过表格单元格链接标签。

相关问题