2016-07-05 83 views
1

我正在嘗試將字幕添加到表格視圖中的單元格。我正在嘗試此代碼,但字幕未顯示。使用swift自定義TableViewCell

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     var cell=tableView.dequeueReusableCellWithIdentifier("topCell", forIndexPath: indexPath) as UITableViewCell 
     cell.textLabel?.text=listPerson[indexPath.row].name 
     cell.detailTextLabel?.text="test" 
     var personImage=UIImage(named: listPerson[indexPath.row].country) 
     cell.imageView?.image=personImage 

     return cell 
    } 

我也想知道是否有可能在單元右側添加另一個圖像。

+0

這應該是可能的。您需要確保故事板內的單元格具有標識符「topCell」才能正常工作。 – onemillion

回答

0

要顯示detailTextLabel你必須設置單元格的樣式屬性界面生成器(⌥⌘4)的督察,以Subtitle文本。

要在右側邊緣添加自定義圖像,您可以編程方式創建UIImageView實例,並將其作爲子視圖添加到附件視圖。

但它可能更適合使用提供插座的自定義單元類。