ios - 使用 swift 自定义 TableViewCell

标签 ios swift uitableview cell

我正在尝试为表格 View 中的单元格添加副标题。我正在尝试这段代码,但没有显示副标题。

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
    }

我还想知道是否可以在单元格右侧添加另一张图片。

最佳答案

要在 detailTextLabel 中显示文本,您必须在 Interface Builder (⌥⌘4) 的属性检查器中将单元格的样式设置为 Subtitle.

要在右边缘添加自定义图像,您可以以编程方式创建 UIImageView 实例,并将其作为 subview 添加到辅助 View 。

然而,使用提供 socket 的自定义单元类可能更合适。

关于ios - 使用 swift 自定义 TableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38201649/

相关文章:

ios - cellForRow At IndexPath 执行一次太少?

ios - 让我的字体作为 "fall-back"工作而不调用它

ios - iPad 上窗口层次结构中的 GHosted Window 是什么以及如何防止它们创建?

iphone - 退出应用程序后 imageview 为空

ios - 使用 Storyboard时如何对第一个屏幕的 View Controller 进行依赖注入(inject)?

ios - 为什么 numberOfRowsInSections : method is invoked 5 times ? 和 numberOfSections 6 倍?

ios - GraphQL 对象按目标映射具有不同模式的 Apollo

swift - 如何访问ParentViewController的功能

arrays - 为什么 Swift Array 的行为与其他语言的 List 不同?

ios - 将 UICollectionView 触摸事件传递给其父 UITableViewCell