ylliX - Online Advertising Network

Few words about dequeueReusableCellWithIdentifier danger….

Well… this should be obvious, but what does “dequeueReusableCellWithIdentifier” mean? More or less it means each cell can be REUSABLE. Yesterday I was working on new Track My TV version and found strange bug – I have UITableView which has subclassed UITableViewCell. And in cellForRowAtIndexPath I’m just filling all data as usual. But my list had ca. 20 series and when I scroll down and up, some labels were disappearing. First I started to look at constraints – my first idea was “something is wrong with them”. But I wasted 2 hours without any result. Today I started from opposite side – commented out almost whole cellForRowAtIndexPath content, and labels were not disappearing. After few minutes I found the reason – I had something like this:

    if(![[item objectForKey:@"aired"] isEqual:[NSNull null]]){
        // some code here 
        cell.days.hidden = YES;

seems to be ok, but what happens when episode has no date? Well, its just hidden so no date is shown. And what happens if I scroll up again? Yes, its still hidden no matter if date is present. So solution was very simple:

cell.days.hidden = NO;

placed before “if” helped. So what does it mean? Cells are really REUSABLE. Keep that in mind and clear everything you don’t want to show.

Leave a Reply