2013-08-27 96 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你想要的。