我知道這個問題被再次問及再次在這裏,但沒有找到我的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];
}
}
AcSummaryCell是UITableViewCell
一個子類,它有一個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連接相反,我越來越喜歡這個圖像 -
現在的問題是如何連接我的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
您是否將xib中的自定義類設置爲ACSummayCell? – karthika
是的,我做過。並嘗試刪除並重新創建連接/ xib等..但沒有運氣。 – Bharat
檢查一切是否連接良好,或者您的xib文件沒有錯誤的引用。 – Raspu