hatdragon.com - i code therefore i am

Thursday, June 25, 2009

Progress Report

So, over the past few evenings, I've been slamming into a brick wall of sorts.

I'm working on the iPhone app pretty much non-stop, and over the past few nights I've been messing with the UITableView and a custom UITableViewCell. This, this has proved interesting. The first evening, the data loaded into my UITableView, but the UITableViewCell never rendered it's contents. I could select a row, I could scroll the table, but you couldn't see what was in them. Night two, was more of the same in a difference manner. Night three was more fruitful. After rewriting the implementation of my UITableViewCell, I ended up getting a background color to at least display for each cell! Woo! Progress. It might now seem like much, but trust me, after two days of fighting with rendering code and having nothing make a difference, it was huge!


So, for those of you following along going, "okay, so, what did you do differently?" Let me try and explain.


In my TableViewController, I have something like the following:





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"myTask";

myTaskCell *cell = (myTaskCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[[myTaskCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
myTaskDetail *task = (myTaskDetail *)[self.Tasks objectAtIndex:indexPath.row];

[cell setTask:task];

return cell;
}



Well, the first issue I had was that I forgot the cast of (myTaskCell *) on the tableView for the dequeueReusableCellWithIdentifier. That threw off a few things in regards to the call to [cell setTask:task] a little further in.


The next issue was in the myTaskCell code itself. Originally, I was just overriding layoutSubviews and crossing my fingers that everything played nicely. That didn't actually didn't go so well. So I did a little research and found this article at the atebits site. So, with a little bit of modification to the myTaskCell code, I switched to using the overriding drawContentView method and low and behold, I now have a blank cell, which is better than the transparent ones I had 20 minutes prior.


Why is my data not displaying? Well it turns out that the font string that I was using was larger than the cell content and when i reduced it from 20 to 14 it seemed to correct the issue. Wallah, text.





- (void)drawContentView:(CGRect)r {

...

normalTextFont = [[UIFont systemFontOfSize:14] retain];
[task.TaskText drawAtPoint:p withFont:normalTextFont];

...
}




So, mostly just putting this out there in hopes that if I run across it again, I have a quick point of reference, or that someone else is able to find it a little more quickly than I was.



Happy Coding!

 

Labels: ,







0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home