Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macprogrammer80

macrumors newbie
Original poster
Apr 22, 2009
15
0
I have a UITableView where I want to make each table view cell's background view change based on a variable from an XML feed. I use the following code:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
	{
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
    }
    
        // Set up the cell
	int notesIndex = [indexPath indexAtPosition: [indexPath length] -1];
	
	// Set up the cell
	bubble1 = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"checkdeselect" ofType:@"png"]];	
	bubble2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];	
	bubble2.image = bubble1;	
	
	bubble1s = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"checklistsselected" ofType:@"png"]];	
	bubble2s = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];	
	bubble2s.image = bubble1s;	

	int checklistSelected = [[textEntries objectAtIndex: notesIndex] objectForKey: @"ticked"];
	UITableViewCell *thisCell = [notesTable cellForRowAtIndexPath:indexPath];
	
	if (checklistSelected != 0)
	{
		cell.selectedBackgroundView = bubble2s;
		cell.backgroundView = bubble2;
	}
	else 
	{
		cell.selectedBackgroundView = bubble2;
		cell.backgroundView = bubble2s;	
	}	
	
	// the note title
	CGRect contentRect = CGRectMake(63, 9, 280, 27);
	textView = [[UILabel alloc] initWithFrame:contentRect];
	textView.text = [[textEntries objectAtIndex: notesIndex] objectForKey: @"item_text"];
	textView.numberOfLines = 1;
	textView.textColor = [UIColor colorWithRed:0.18431373 green:0.25098039 blue:0.32941176 alpha:1.0];
	textView.highlightedTextColor = [UIColor whiteColor];
	textView.backgroundColor = [UIColor clearColor];
	textView.font = [UIFont boldSystemFontOfSize:16];
	[cell addSubview:textView];
	
    return cell;
}

The issue is that the cell is receiving the right information, the correct if statement is even running, but it's not updating the UITableViewCell to the right background view and selected background view. How can I make these values dynamic?

Thanks in advance!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.