我是使用 swift 2.2 进行 Ios 编程的新手
我想要实现的目标是在 uitableviewcell 或 uitableviewcells 中插入两个文本字段
例如单元格中的文本将采用这种格式
“A vs B”
我想在 VS 两侧插入文本字段 所以我希望它看起来像这样“A[Textfield] vs [Textfield]B”
任何形式的帮助将不胜感激
最佳答案
创建具有两个文本字段导出的 UITableViewCell 子类:
class TextFieldsCell: UITableViewCell { @IBOutlet var textfield1: UITextField! @IBOutlet var textfield2: UITextField! }
在 IB 中,选择表格 View ,然后在属性检查器中将“原型(prototype)单元格”设置为“1”,将原型(prototype)单元格添加到表格 View 中:
- 在 IB 中,使用自动布局在单元格内布局文本字段。 (跳过自动布局实现的细节)
- 在 IB 中,选择表格 View 单元格,然后在属性检查器中将其“标识符”更改为“TextFieldsCell”:
- 在 IB 中,选择表格 View 单元格,然后在身份检查器中将其“Class”更改为“TextFieldsCell”:
- 在 IB 中,将
TextFieldsCell
的 IBOutlet 与相应的文本字段连接:
在包含 TableView 的 View Controller 中,实现以下内容:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 2; } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell: TextFieldsCell = tableView.dequeueReusableCellWithIdentifier("TextFieldsCell") as! TextFieldsCell return cell }
如果您正确设置了所有内容,您应该在下次运行时看到以下内容:
关于ios - 将文本字段添加到 UITableview 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51590653/