我正在尝试从按下的单元格返回titleField或标题值.经过一些挖掘后,我发现了一些应该可行的代码,但是我得到了错误:
"UITableViewCell"类型的值没有成员'titleField'
对于标题,标签等所有其他项目也是如此.
extension SearchViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return posts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier:"searchCell", for: indexPath)
as! CustomTableViewCell
cell.titleField?.text = posts[indexPath.row].caption
cell.descriptionField?.text = posts[indexPath.row].description
cell.tagsField?.text = posts[indexPath.row].tags
let photoUrl = posts[indexPath.row].photoUrl
let url = URL(string: photoUrl)
cell.SearchImage.sd_setImage(with: url, placeholderImage: nil)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let indexPath = tableView.indexPathForSelectedRow
//getting the current cell …Run Code Online (Sandbox Code Playgroud)