2017-02-19 87 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