如何访问静态单元 [英] How to access to a static cell

查看:57
本文介绍了如何访问静态单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我直接在情节提要中创建了一个TableView;该tableView在4个部分中包含8个静态单元格(基本样式);现在,我该如何通过代码编辑这些单元格?例如,要更改textLabel,backgroundColor,ecc分隔符
,我尝试为每个cel设置一个标识符,但没有用...

I created a TableView directly in the storyboard; this tableView contains 8 static cells (style basic) in 4 section; now, how could I edit via code these cells? for example for to change textLabel, backgroundColor, separator ecc I tried to set an identifier to each cel but didn't work...

推荐答案

对于在情节提要中创建的静态单元格,只需将要编辑的元素设置为 IBOutlet ,即可通过ctrl从情节提要中拖动到相应的视图控制器,最终得到这样的结果:

For static cells created in the storyboard, you can simply set the IBOutlet for the elements you want to edit by ctrl-dragging from the storyboard to the corresponding view controller, to end up with something like this:

class MyViewController: UIViewController {
  @IBOutlet weak var cell1: UITableViewCell!
  @IBOutlet weak var cell2: UITableViewCell!
}

然后,您可以使用<$访问基本视图中的内置元素c $ c> cell1.textLabel 等。

查看有关设置 IBOutlets 的文档

要更改背景颜色,可以直接在情节提要UI中进行更改,或访问 backgroundColor 属性。您可能需要阅读 UITableViewCell类参考

To change the background color, you can do it in the storyboard UI directly or access the backgroundColor property. You might want to read the UITableViewCell Class Reference.

这篇关于如何访问静态单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆