2012-05-24 132 views
0

我使用IB和Storyboards在UITableView中創建了自定義單元格。下面的代碼是加載該自定義單元的代碼;問題是雖然cA.cBusName和cA.cOrderDate中有有效的數據,但cell標籤(cell.busNameLabel.text,cell.orderDateLagbel.text)沒有設置。 問題是:爲什麼這不起作用?爲什麼UITableCell不顯示內容

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

    static NSString *CellIdentifier = @"CustomerListingsCell"; 

    CustomerListingsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[CustomerListingsCell alloc] 
       initWithStyle:UITableViewCellStyleDefault 
       reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 
    SingletonListOfCustomers *shareInstance = [SingletonListOfCustomers sharedInstance]; 
    cArray *cA = [shareInstance.listOfCustomers objectAtIndex: indexPath.row]; 

    cell.busNameLabel.text = cA.cBusName; 
    cell.orderDateLabel.text = cA.cOrderDate; 

    NSLog(@"\n\nindexPath.row: %d, busNameLabel: %@, orderDateLabel: %@", indexPath.row, cA.cBusName, cA.cOrderDate); 
    NSLog(@"\nindexPath.row: %d, cell.busNameLabel: %@, cell.orderDateLabel: %@", indexPath.row, cell.busNameLabel.text, cell.orderDateLabel.text); 

    return cell; 

} 

CustomerListingsCell定義爲:

@interface CustomerListingsCell : UITableViewCell { 

} 

@property (nonatomic, strong) IBOutlet UILabel *busNameLabel; 
@property (nonatomic, strong) IBOutlet UILabel *orderDateLabel; 

@end 

的的NSLog語句輸出是:

2012-05-24 14:01:55.363空白麪料[4876:F803]

indexPath.row:0,busNameLabel:隱藏的針跡,orderDateLabel: 2012-05-24 2012-05-24 14:01:5 5.364空白麪料[4876:f803] indexPath.row:0,cell.busNameLabel:(null),cell.orderDateLabel: (null)2012-05-24 14:01:55.365 Blank Fabrics [4876:f803]

indexPath.row:1,busNameLabel:Prager,Software,orderDateLabel: 05/24/2012 2012-05-24 14:01:55.373 Blank Fabrics [4876:f803] indexPath.row:1,cell.busNameLabel: (null),cell.orderDateLabel: (null)

+0

你能舉一個2個NSLog語句打印的例子嗎? (也許只是'NSLog(@「Cell:%@」,cell);'? –

+0

根據請求更新NSLog語句... – SpokaneDude

+0

嘗試使用cell.textLabel.text = cA.cBusName;如果它工作,那麼你的自定義tableviewcell上的連接是錯誤的。 – 3lvis

回答

1

您的IBOutlets是否爲這兩個標籤設置?檢查cell.busNameLabel是否不爲零...

+0

是的,它們設置正確 – SpokaneDude

+0

iTukker ...是的,他們是零(分配後檢查)...這怎麼可能? – SpokaneDude

+0

正如我在我的答案中所寫的那樣:創建單元格時未加載nib文件。 – vikingosegundo

相關問題