我目前正在试图弄清楚如何设置文本字段的占位符文本.文本字段位于单元格内.我想要分配给占位符的文本包含在一个数组中.
我之前做过类似的设置图像,看起来像这样
cell?.imageView?.image = row1images[indexPath.row]
所以,使用那种我认为使用的意识形态……
cell?.textField?.text = nil cell?.textField?.placeholder = row1[indexPath.row]
… 会工作.但是,我收到错误“类型的值’UITableViewCell’没有成员’textField’”
解决方法
试试这个…
如果您在自定义单元格上有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 }