将文本字段添加到UITableview单元格 [英] Adding a text field to a UITableview Cell

查看:117
本文介绍了将文本字段添加到UITableview单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用swift 2.2进行Ios编程的新手

Am new to Ios programming with swift 2.2

我想要实现的是在uitableviewcell或uitableviewcells中插入两个文本字段

What am trying to achieve is inserting two text fields in a uitableviewcell or uitableviewcells

例如单元格中的文本将采用这种格式

for example the text in the cell will be of this format

A vs B

我想在VS
的两边插入文本字段,所以我希望它看起来像这样的A [Textfield] vs [Textfield] B

i want to insert text fields on both sides of the VS so i want it to look like this "A[Textfield] vs [Textfield]B"

任何形式的帮助将不胜感激

any sort of help will be appreciated

推荐答案


  1. 创建UITableViewCell的子类有两个文本字段:

  1. Create a subclass of UITableViewCell with two text field outlets:

class TextFieldsCell: UITableViewCell {
    @IBOutlet var textfield1: UITextField!
    @IBOutlet var textfield2: UITextField!
}


  • 在IB中,选择您的表格视图并添加原型单元格通过在属性检查器中将原型单元格设置为1来查看表格视图:

  • In IB, select your table view and add a prototype cell to your table view by setting "Prototype Cells" to "1", in attributes inspector:


    1. 在IB中,使用autolayout布局单元格内的文本字段。 (跳过autolayout实现的详细信息)


    1. 在IB中,选择您的表格视图单元格,并在属性检查器中将其标识符更改为TextFieldsCell:


    1. 在IB中,选择您的表格视图单元格,并在身份检查器中将其Class更改为TextFieldsCell:


    1. 在IB中,连接 TextFieldsCell 我的包含相应文本字段的BOutlets:

    1. In IB, connect TextFieldsCell's IBOutlets with the corresponding text fields:


    1. 在包含表格视图的视图控制器中,实现以下内容:

    1. In your view controller which contains the table view, implement the following:

    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
    }
    


  • 如果你正确设置了一切,你应该在下次运行中看到这个:

  • If you set everything up properly, you should see this on the next run:

    这篇关于将文本字段添加到UITableview单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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