2016-07-05 102 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实例,并将其作为子视图添加到附件视图。

但它可能更适合使用提供插座的自定义单元类。

相关问题