I have a UITableView named "TaskTable" and I am adding a label in the contentview of each cell of the TaskTable in this method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
My label tag is 50 and I am using in built cell of table view for that not custom cell.
now when i try to remove my lable from TaskTable using this code:
for(UILabel *lbl in [cell subviews])
{
if(lbl.tag == 50)
{
[lbl removeFromSuperview];
}
}
The code isn't entering this if condition. Why doesn't it find the label? Is this happening because I am using the built in cell that only find its own text-label, or there is some other issue that I am missing?
You've said you're adding it to the content view of your cell. However your code above is going through the subviews of your cell itself - this only goes one level deep, so it will return the content view, but not the subviews of your content view.
for(UILabel *lbl in [cell.contentView subviews])
{
if(lbl.tag == 50)
{
[lbl removeFromSuperview];
}
}
Should work, but really a custom cell subclass with the label as a property would be better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With