Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is UItableViewCell viewWithTag returning nil?

I am using IOX8 and Xcode 6. I created a table with a customtype cell in storyboard, and I placed a label in it. I entered a tag number for the label in the IB, so that I could retrieve a reference to the label in my code. But when I try to get a reference to the label inside my "cellForRowAtIndexPath", using viewWithTag I get a NIL for the label :

This are the two lines of code that are important in cellForRowAtIndexPath:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlayerCell"];


UILabel *nameLabel = (UILabel *)[cell viewWithTag:1];

The "cell viewWithTag:1" line returns NIL, I don't understand why.

I also tried "cell.contentView withWithTag:1" and that did not work either.

Is this a bug in IOS 8 or Xcode 6?

thanks

-Malena

like image 456
malena Avatar asked Sep 27 '14 05:09

malena


3 Answers

Uncheck Size Classes option in the storyboard and clean & build the app. It should work now.

like image 112
Karthik damodara Avatar answered Nov 06 '22 01:11

Karthik damodara


I met the same problem when I was using IOS8 and Xcode 6.1. I found that if I enable the Size Classes, viewWithTag always return nil. I think it may be a bug for Xcode 6.x. Just disable the Size Classes, everything goes ok.

like image 5
angeldsWang Avatar answered Nov 05 '22 23:11

angeldsWang


Try to make the view 'installed', check this link:

like image 2
William Hu Avatar answered Nov 06 '22 00:11

William Hu