0

我知道这个问题在这里一次又一次地被问到,但没有找到任何解决我的问题的方法。我正在通过 xib 创建一个自定义 UITableViewCell 并尝试加载它。在我的名为ACSummaryVC的 VC 中

- (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];
    }
}

AcSummaryCell是的子类,UITableViewCell它有一个UILabel名为 acLabel 的 IBOutlate。当我编译项目时,我得到以下错误-

`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 收到错误消息?我做错了什么?

编辑:-根据下面的 Mani 的回答,我正在将延迟连接到文件所有者,这是错误的,而是我必须将延迟连接到自定义单元格。但是当我尝试这个时,我没有让我的延迟连接,而是我得到了像这张图—— 在此处输入图像描述

现在的问题是如何将我的 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
4

4 回答 4

5

您设置了错误的插座连接。这是因为您已将标签的出口连接到文件的所有者。从文件所有者中删除该标签出口连接,并将出口连接到您的自定义单元格。它应该工作。

于 2013-08-27T05:52:00.087 回答
1

按照这个...自定义tableview单元 UITableViewCell标题和副标题之间的空间-iOS

或者这个很棒的教程

http://www.appcoda.com/customize-table-view-cells-for-uitableview/

于 2013-08-27T05:55:08.327 回答
1

正确遵循此代码....

音频单元.h

#import<UIKit/UIKit.h>

@interface AudioCell : UITableViewCell

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


@end

音频单元.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 与子类链接.... 在此处输入图像描述

于 2013-08-27T06:30:54.383 回答
0

我看到你的错误:

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

对于连接到 IBOutlet,只需选择编辑器(显示助手编辑器)-> 然后选择自动AcSummaryCell.h--> 然后拖动并连接所需的 IBOutlet。

于 2013-08-27T06:52:26.857 回答