我有UITableView,自定义UITableViewCell有两个uitextfiled 我想获得每个uitextfiled的文本作为数组 还有在UITableView中添加新单元格的按钮
显示我该如何处理这个问题 编辑 这是自定义uitabelcell类
@IBOutlet weak var treatmentCount: UITextField!
@IBOutlet weak var treatmentText: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
和这个UITabelView控制器
var tretments = [(name:String,count:String)](count: 15 , repeatedValue: (name: "" , count: ""))
var tretmentNames = ""
var tretmnetCounts = NSMutableDictionary()
var count = 5
@IBOutlet weak var orderTableView: UITableView!
@IBAction func addItem(sender: AnyObject) {
count += 1
save()
orderTableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = orderTableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! OrderItemTableViewCell
cell.treatmentText.text = tretments[indexPath.row].name
cell.treatmentCount.text = tretments[indexPath.row].count
return cell
}
func save() {
for rowIndex in 0...self.orderTableView.numberOfRowsInSection(0) {
let indexPath : NSIndexPath = NSIndexPath(forItem: rowIndex, inSection: 0);
if (self.orderTableView.cellForRowAtIndexPath(indexPath) != nil) {
let cell = self.orderTableView.cellForRowAtIndexPath(indexPath) as! OrderItemTableViewCell
print(indexPath.row)
tretments.insert((name: cell.treatmentText.text!, count: cell.treatmentCount.text!),atIndex:indexPath.row)
print("Name:\(cell.treatmentText.text), Count: \(cell.treatmentCount.text)")
}
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return count
}
我需要在textfield中获取所有用户输入,并且还跳过其他用户没有在textfield中输入任何文本 当用户尝试在uitabelview上滚动时,我的代码中存在问题
答案 0 :(得分:0)
您可以创建一个插座集合并对其进行迭代以获取每个文本字段值。如果要保留订单,请使用标签属性。