1

我正在嘗試使用自定義單元格的tableview。IBOutlet未啓動

我創建了2個文件.m和.h,它們指向我的類CustomCell。 下面是代碼:

#import <UIKit/UIKit.h> 

@interface CustomCell : UITableViewCell 
{ 
    IBOutlet UIImageView *miniLogo; 
    IBOutlet UILabel *cellText; 
    IBOutlet UIButton *deleteButton; 
} 

@property (strong, nonatomic) IBOutlet UIImageView *miniLogo; 
@property (strong, nonatomic) IBOutlet UILabel *cellText; 
@property (strong, nonatomic) IBOutlet UIButton *deleteButton; 

@end 

------------------------------------------------------------- 

#import "CustomCell.h" 

@implementation CustomCell 


@synthesize miniLogo,cellText, deleteButton; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

-(void)layoutSubviews{ 
    [super layoutSubviews]; 
} 

/* 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
}*/ 

@end 

憑藉的.xib文件,我設計了我的手機,並連接IBOutlets,並設置單元格的標識。

在該表中與用戶自己定製的細胞,我稱之爲細胞的方法的tableView:cellForRowAtOndexPath:是這樣的:

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellsIdentifier ]; 
    if (cell == nil){ 
     UIViewController *tempVC = [[UIViewController alloc] initWithNibName:@"CustomCell" bundle:nil]; 
     cell = (CustomCell *)tempVC.view; 
    } 

當我啓動我的應用程序,標籤顯示設置的文本,圖像意見顯示正確的圖像。但按鈕不出現。事實上,當設置斷點時,我看到我的按鈕的地址始終爲0x00000000(意味着我的按鈕未啓動)。

請問有人可以幫我解決這個問題。

+0

您確定您已連接IB的deleteButton插座嗎? –

+0

將它們帶出界面。你不需要它們被合成和自動合成 –

+0

我的按鈕連接到我的.h文件。 我在界面中刪除了我的IBOutlet,但沒有更改.... – zbMax

回答

1

我發現了這個問題。

在他的viewDidLoad我在做什麼:

UINib *cellNib = [UINib nibWithNibName:@"myCells" bundle:nil]; 
    [self.tableView registerNib:cellNib forCellReuseIdentifier:CellsIdentifier]; 

但因爲我已經改變了我的.xib的名字,我是不加載正確的接口。 奇怪的是,我沒有任何名爲「myCells」的nib。 也許我應該在我的項目上執行一個「清理」...