我已将 链接UITextView到我的自定义单元格类,当我调用dequeueReusableCell## 时,我将它分配给常量单元格作为我的CustomCellClass.
我无法弄清楚为什么会发生这种情况。当我检查日志控制台旁边的变量部分时,它说一切都为零。
然而,当我打开的TableViewCell,我发现"_imageView"和"_textLabel",如果我指定我的价值观这些,它显示了。即使那样,我也找不到UITextView那里。
谢谢你的帮助。
自定义单元格类的代码:
class PostCell: UITableViewCell
{
@IBOutlet weak var postImageView: UIImageView!
@IBOutlet weak var postTextView: UITextView!
@IBOutlet weak var postName: UILabel!
}
Run Code Online (Sandbox Code Playgroud)
我分配值的函数:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier , for: indexPath) as! PostCell
let cellPost = self.posts[indexPath.row]
cell.textLabel?.text = "Hola"
cell.postName.text = cellPost._text
cell.imageView?.image = UIImage(named: "UV_Logo-12")
return cell
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,textLabel并且imageView不是自定义类中的 var 名称。
viewDidLoad 函数:
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
queryPosts()
tableView.delegate = self
tableView.dataSource = self
self.tableView.register(PostCell.self, forCellReuseIdentifier: cellReuseIdentifier)
}
Run Code Online (Sandbox Code Playgroud)
两个问题:
queryPosts()应该填充数据源阵列必须设置delegate和datasource调用方法前。override func viewDidLoad()
{
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
queryPosts()
}
Run Code Online (Sandbox Code Playgroud)