小编Zab*_*lah的帖子

如何在swift中使用Textfield制作UITableview?

我想在每个单元格中创建一个包含文本字段的表格视图,

我在swift文件中有一个自定义类:

import UIKit

public class TextInputTableViewCell: UITableViewCell{

    @IBOutlet weak var textField: UITextField!
    public func configure(#text: String?, placeholder: String) {
        textField.text = text
        textField.placeholder = placeholder

        textField.accessibilityValue = text
        textField.accessibilityLabel = placeholder
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的ViewController中我有

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

    let cell = tableView.dequeueReusableCellWithIdentifier("TextInputCell") as! TextInputTableViewCell

    cell.configure(text: "", placeholder: "Enter some text!")

     text = cell.textField.text

    return cell

}
Run Code Online (Sandbox Code Playgroud)

这很好用:

在此输入图像描述

但是当用户在文本字段中输入文本并按下按钮时,我想将每个文本字段的字符串存储在一个数组中.我试过了

text = cell.textField.text
println(text)
Run Code Online (Sandbox Code Playgroud)

但它没有打印就像它是空的

我怎样才能使它工作?

cell uitableview uitextfield ios swift

14
推荐指数
1
解决办法
3万
查看次数

如何从arc4random中排除特定的整数

我想得到一个随机数,arc4random_uniform()但不包括像这样的数组中的数字

var numbersArray = [8,15,10,3,7]
var randomNumber = arc4random_uniform(20)
Run Code Online (Sandbox Code Playgroud)

如果arc4random_uniform()给我任何数字,numbersArray我希望它得到一个不是来自的数字numbersArray

我试过这个

func getRandomGroup() -> Int {
    for numbers in numbersArray {
        if numbers == randomNumber {
             var randomNumber = arc4random_uniform(20)
        }
    }
    return randomNumber
}
Run Code Online (Sandbox Code Playgroud)

但它似乎没有奏效

arc4random swift

0
推荐指数
1
解决办法
1288
查看次数

标签 统计

swift ×2

arc4random ×1

cell ×1

ios ×1

uitableview ×1

uitextfield ×1