Question

I am not sure which one to use? cell.contentView sometimes give me weird errors like [uiview settext]...?? I was trying to setText to a UILabel*

Was it helpful?

Solution

The one to use depends on how you created the cell in the first place. If you added your UILabel as a subview of the contentView (e.g. [cell.contentView addSubview:myLabel]), then you would use [cell.contentView viewWithTag:1] to retrieve it (assuming the label actually has a tag of 1).

However, I would caution you about using -viewWithTag: in the first place. It's fairly useful for poking at stuff, but it's not very reliable (because if two views have the same tag, you're only going to get one of them back) and it's not very efficient (it has to traverse the subviews every time you use it). I would instead recommend creating a UITableViewCell subclass that has properties for your custom views, so you can access them directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top