Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 根据单元格中textfield中输入的值动态增加tableview单元格_Ios_Swift_Uitableview_Uitextfield - Fatal编程技术网

Ios 根据单元格中textfield中输入的值动态增加tableview单元格

Ios 根据单元格中textfield中输入的值动态增加tableview单元格,ios,swift,uitableview,uitextfield,Ios,Swift,Uitableview,Uitextfield,我是斯威夫特的新手。我有一个带有一个自定义UITableViewCell的UITableView。它有一个UITextfield。默认情况下,numberOfRows为1 当我在文本字段中输入一个整数值(x)并按enter键时,tableview应该附加x个tableviewcells,每个单元格都应该有一个文本字段 这是我的密码: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPat

我是斯威夫特的新手。我有一个带有一个自定义UITableViewCell的UITableView。它有一个UITextfield。默认情况下,numberOfRows为1

当我在文本字段中输入一个整数值(x)并按enter键时,tableview应该附加x个tableviewcells,每个单元格都应该有一个文本字段

这是我的密码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell : TableViewCell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as! TableViewCell
    cell.textField?.text = "Created"
    cell.textField.tag = indexPath.row
    cell.textField.addTarget(self, action: #selector(textFieldShouldReturn()), forControlEvents: <#T##UIControlEvents#>)

    return cell
}
func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格{
将单元格:TableViewCell=self.tableView.dequeueReusableCellWithIdentifier(“单元格”)设为!TableViewCell
cell.textField?.text=“已创建”
cell.textField.tag=indexPath.row
cell.textField.addTarget(self,action:#选择器(textFieldShouldReturn()),forControlEvents:)
返回单元
}

要实现所需功能,请在用户完成编辑时设置iAction,以检查插入的值是否为有效数字,如果为有效数字,请增加数据源上的记录数,并调用tableView.reloadData()刷新表

在cellForRowAtIndexPath上,您可以对该行进行验证,以防您希望单元格与第一个单元格不同,如下所示

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell: UITableViewCell!

    if indexPath.row == 0 {
        cell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
        cell.textField?.text = "Created"
        cell.textField.tag = indexPath.row
        UITextField().addTarget(self, action: #selector(customMethod), for: .editingDidEnd)
    } else {
        cell = self.tableView.dequeueReusableCellWithIdentifier("otherCell") as! UITableViewCell
        cell.textLabel?.text = "Created programatically"
    }

    return cell
}

我不清楚你要什么。“输入n个值”和“增加n倍”是什么意思?