2013-03-24 13 views
0

使用NSCoder時,我在哪裏添加我的自定義tableview單元格標籤在我的UITableview中? 我已經創建了UITableViewCell類並將所有內容都吸引到界面構建器中。使用NSCoder時,我在哪裏添加我的自定義tableview單元格標籤在我的UITableview中?

我試圖替換cell.textLabel.text = oneName.name; withcell.label.text = oneName.name;它只是顯示一個黑色的方塊。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
    if (!cell) { 
     cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    // Configure the cell... 
    NSUInteger row = [indexPath row]; 
    DrillObject *oneName = [self.addDrill objectAtIndex:row]; 
    cell.textLabel.text = oneName.name; 



    return cell; 
} 
+0

「使用NSCoder時」是什麼意思? – Matt 2013-03-24 07:00:25

+0

我只是說,因爲通常的方式來實現這個不會工作cell.label.text = [addDrill objectAtIndex:indexPath.row]; – 2013-03-24 13:48:20

回答

0

您確定您的標籤尺寸合適嗎?當使用自定義單元格時,我真的推薦使用免費的Sensible TableView框架。框架會自動將對象的數據加載到自定義標籤中,並且還會在需要時自動調整標籤/單元格的大小。

+0

這個標籤太小了,非常感謝!!!!! – 2013-03-24 14:00:56

0

有拖選項來添加標籤到您的CustomCell類像你想在這裏:
1-廈門國際銀行在文件中添加標籤到你的細胞和分配它一個標籤,然後創建這樣一個getter:

-(UILabel*)label 
{ 
    id label = [self viewByTag:3]; 
    if([label isKindOfClass:[UILabel class]]) 
    { 
      return label; 
    } 
    return nil; 
} 

2-創建在init方法的標籤和不要忘記設置標籤的背景色清除顏色這樣的:

UILabel *label = [UILabel alloc] initWithFrame:myFreame]; 
[label setBackgroundColor:[UIColor clearColor]]; 

// now you should have property on .h file like this 
@property (nonatomic, weak) UILabel *label; 
// so back to the init dont forget to do this 

_label = label; 

那它。

+0

對於第一個是這樣的,如果即時通訊使用故事板,因爲它給'self.view'錯誤 – 2013-03-24 13:57:14

+0

你得到了什麼錯誤?如果你從CustomCell類執行此操作,那麼只需執行此操作[self viewByTag:3] without view。 – 2013-03-24 14:39:59

相關問題