2016-03-04 224 views
-1

這是我的代碼「的UITableViewCell」不顯示標籤

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Configure the cell... 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];} 

    self.credits = (UILabel*)[cell viewWithTag:101]; 
    self.credits.text = @"Available Credits"; 
     cell.backgroundColor = [UIColor redColor]; 
    self.credits.textColor = [UIColor blackColor]; 
    [cell.contentView addSubview:self.credits]; 

學分是這裏的標籤

+0

是你的self.credits零? –

+0

你可以顯示'self.credits' –

+0

你在哪裏分別創建'UILabel'標籤101分配給標籤? – vadian

回答

0

您存儲單元的標籤在你UIViewController,然後嘗試addSubview在內容視圖。

這個正確的方法應該是:

  1. 創建的UITableViewCell
  2. 一個子類分配該小區內的標籤作爲屬性(可能是通過代碼,由廈門國際銀行)
  3. cellForRowAtIndexPath:使用該屬性名稱,分配Available Credits

cellForRowAtIndexPath應該是這樣的結尾:

- (MyCustomUITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    MyCustomUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    self.myNewProperty.text = @"Available Credits"; 
}