2013-08-27 137 views
0

我知道这个问题被再次问及再次在这里,但没有找到我的problem.I'm通过XIB创建一个自定义的UITableViewCell,并试图解决任何以加载它,在我的VC叫ACSummaryVC创建自定义UITableViewCell?

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

    static NSString *CellIdentifier = @"SimpleTableCell"; 

    AcSummaryCell *cell = (AcSummaryCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AcSummaryCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 
} 

AcSummaryCellUITableViewCell一个子类,它有一个UILabel IBOutlate称为acLabel.when我编译项目我获得以下错误 -

`Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ACSummaryVC 0x71465c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key acLabel.'` 

我创建康恩在AcSummayCell类中的acLabel,但我从ACSummaryVC错误?我做错了什么?

编辑: - 根据摩尼的答案波纹管我连接outlate到文件的所有者,这是错误的,而不是我来outlate连接到定制cell.but当我尝试这方面,我没有得到我的outlate连接相反,我越来越喜欢这个图像 - enter image description here

现在的问题是如何连接我的outlate自定义单元格? 这里是我的AcSummayCell.h

@interface AcSummayCell : UITableViewCell 
@property(nonatomic, retain)IBOutlet UILabel* acLabel; 
@property(nonatomic, retain)IBOutlet UILabel* namelbl; 
@property(nonatomic, retain)IBOutlet UILabel* cBalancelbl; 
@property(nonatomic, retain)IBOutlet UILabel* avBalancelbl; 

和AcSummayCell.m

#import "AcSummayCell.h" 

@implementation AcSummayCell 
@synthesize acLabel = _acLabel; 
@synthesize namelbl = _namelbl; 
@synthesize cBalancelbl = _cBalancelbl; 
@synthesize avBalancelbl = _avBalancelbl; 

- (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 
+0

您是否将xib中的自定义类设置为ACSummayCell? – karthika

+0

是的,我做过。并尝试删除并重新创建连接/ xib等..但没有运气。 – Bharat

+0

检查一切是否连接良好,或者您的xib文件没有错误的引用。 – Raspu

回答

5

你必须设置一个错误的出口连接。这是因为您已将标签的插座连接到文件的所有者。将标签出口连接移出文件所有者,并将指向您定制单元的插座连接起来。它应该工作。

+0

是的。你说得对。 –

+0

你可以请解释它,因为当我试图连接到自定义单元格它没有显示我的外联连接,而是显示accessoryView,backgroundView等 – Bharat

+0

我已编辑我的问题,请检查。 – Bharat

1
+0

谢谢mayank我已经按照教程,但没有得到的东西“连接指向您的自定义单元格的插座”..当我右键单击我的自定义单元格在笔尖连接outlate它不显示我outlates与连接? – Bharat

+0

我编辑了我的问题,请检查。 – Bharat

+0

你已经为你的标签声明了属性... ??? –

1

关注该码正确....

AudioCell.h

#import<UIKit/UIKit.h> 

@interface AudioCell : UITableViewCell 

@property (strong, nonatomic) IBOutlet UILabel *titleLabel; 
@property (strong, nonatomic) IBOutlet UILabel *artistLabel; 
... 


@end 

AudioCell.m

#import "AudioCell.h" 

@implementation AudioCell 

@synthesize titleLabel = _titleLabel, artistLabel = _artistLabel; 

- (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 

现在实现你在的TableView数据源类的代码....

#import "AudioCell.h" 
..... 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"AudioCell"; 

AudioCell *cell = (AudioCell *)[self.audioFeedTable dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; 
    cell = (AudioCell *)[nibArray objectAtIndex:0]; 
    [cell configurePlayerButton]; 
} 

// Configure the cell.. 


cell.titleLabel.text = [nameArray objectAtIndex:indexPath.row]; 
cell.artistLabel.text = [commentsArray objectAtIndex:indexPath.row]; 
.... 

return cell; 
} 

链接您的自定义TableViewCell通过同样的方式,子类.... enter image description here

+0

我在做同样的事情。 – Bharat

+0

正在运作? –

+0

是的它的工作。+ 1为你的伟大的帮助 – Bharat

0

我看到你的错误:

不指定单元格级,并在您customCell重用标识符首先创建自定义单元格AcSummaryCell:UITableViewCell,然后在nib单元格中为tableCell选择class。还要在NIB中分配小区标识符。如果正确,您的单元格必须在对象字段中显示 AcSummaryCell-SimpleTableCell

对于IBOutlet的连接,只需选择编辑器(显示助理编辑器) - >然后选择自动 - AcSummaryCell.h - >然后拖动和连接IBOutlet你想要的。