2017-02-19 97 views
-1

我在UITableViewCell中使用UITextField,并为每个textFields分配tags。但是在滚动tableView之后,textFields的标签被改变了。我正在使用swift 3.如何在滚动时使textFields的标签保持不变?我不使用故事板。swift中的TableView 3

+2

你能表现出一定的代码?你的TableView数据源的代码,特别是在你的'cellForRow' – Glenn

+0

[iOS Swift项目中如何访问UITableViewCell contentView的子视图中的变量]的可能重复(https://stackoverflow.com/questions/34701707/how-to-访问变量-中之子视图-的-的UITableViewCell-内容查看功能于IOS-S) –

回答

0

斯威夫特3指定文本字段标签作为indexPath.row

试试这个代码: -

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "ReuseIdentifer", for: indexPath) as UITableViewCell 
     cell.textField.tag = indexPath.row 
    } 
0

可以将标签属性设置为indexPath.row,它会正常工作。 正如如下,

在的cellForRowAtIndexPath:写:

let cell = tableView.dequeueReusableCell(withIdentifier:"ReuseIdentifer", for: indexPath) as! UITableViewCell 

cell.textField.tag = indexPath.row