Quickly set fields to fill text fields

I'm currently trying to figure out how to set the text of a text field placeholder. The text box is inside the cell. The text that I would like to assign to the placeholder is contained in an array.

Earlier, I did this with image settings, and it looked like this:

cell?.imageView?.image = row1images[indexPath.row]

So, using this ideology, I thought, using ...

cell?.textField?.text = nil
cell?.textField?.placeholder = row1[indexPath.row]

... will work. However, I get the error "Value of type" UITableViewCell does not have a textField element ''

+4
source share
2 answers

Try it...

textField , cellForRowAt.

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

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

            cell .yourTextField.attributedPlaceholder = NSAttributedString(string: row1[indexPath.row],
                                                                       attributes: [NSForegroundColorAttributeName: UIColor.black])


            return cell
    }
0

" " UITableViewCell . " . prototype cell, TextField, custom cell, CustomCellClass. , , reusable cell UITableViewCell, CustomCellClass.

, .

0

Source: https://habr.com/ru/post/1675224/


All Articles