i具有自定义UItableViewCell
的UItableView
。每个单元格中都有UItextField
。现在,我希望用户能够通过键入键盘上的下一个按钮来移至下一个TextField。我已经知道我们可以在 cellforrowatIndExpath
cell.textField.tag = indexPath.row
,然后移至下一个字段
if let nextField = self.view.viewWithTag(textField.tag + 1) as? UITextView {
nextField.becomeFirstResponder()
} else {
textField.resignFirstResponder()
}
,但是在我的情况下,我们有多个部分,所以这个
cell.textfield.tag = indexpath.Row
行不通。有线索吗?预先感谢。
您可以做到这一点 1(将Textfield的标签作为部分组合;行
textfield.tag = indexPath.section*1000 + indexPath.row
并使用打击代码获取:
let Row = textfield.tag % 1000
let Section = (textfield.tag - Row)/1000
或 2(您可以通过在Textfield的任何代表方法中使用以下代码来获取TableView单元格的部分和行值:
let item:UITableViewCell = textField.superview?.superview as! UITableViewCell
let indexPath = table_view.indexPath(for: item)
print(" Section :(indexPath?.section)")
print(" Row :(indexPath?.row)")
检查部分&行值,然后设置textfield的headfirstresponder,并具有所需的条件(根据您的部分和行数(
谢谢大家的回答,我无法理解我通过对数据源进行调整一点
来做到这一点 func getBaseValueCount(currentSection:Int) -> Int {
var count = 0
if currentSection == 0 {
return count
}
else{
for i in 0..<currentSection {
count = count + (self.formSections[i].fields?.count)!
}
}
return count
}
然后在CellForrowatIndExpath中
cell.txtAnswer.tag = self.getBaseValueCount(currentSection: indexPath.section) + indexPath.row
再次感谢。