3

I have a UITableView with a prototype UITableViewCell with the identifier contact. In interface builder, I built the cell correctly and have all the elements set to the right tags. When I try to edit a UILabel in the cell that has the tag 101 using cell.viewWithTag, the method returns nil. This seems to only be a problem on iOS 8. I am using storyboards and Swift. Here is the code in tableView:cellForRowAtIndexPath:

let contact = contacts[indexPath.row]
println("Contact: \(contact)")
cell = tableView.dequeueReusableCellWithIdentifier("contact") as UITableViewCell
(cell.contentView.viewWithTag(101) as UILabel).text = contact["name"]! as String
4

1 に答える 1

6

これを使ってみてください

let contact = contacts[indexPath.row]
println("Contact: \(contact)")
cell = tableView.dequeueReusableCellWithIdentifier("contact", forIndexPath: indexPath) as UITableViewCell
(cell.contentView.viewWithTag(101) as UILabel).text = contact["name"]! as String
于 2014-09-25T04:53:38.033 に答える