Here are my delegate methods...
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger) section
{
return [locationLevels count];
}
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
CGRect CellFrame = CGRectMake(0, 0, 447, 210);
UILabel *levelName = [[UILabel alloc]initWithFrame:CGRectMake(170,6,280,17)];
UILabel *levelStatus = [[UILabel alloc]initWithFrame:CGRectMake(170,25,280,17)];
UILabel *levelTime = [[UILabel alloc]initWithFrame:CGRectMake(175,44,300,17)];
UILabel *levelHeight = [[UILabel alloc]initWithFrame:CGRectMake(175,63,300,17)];
UILabel *levelScore = [[UILabel alloc]initWithFrame:CGRectMake(175,82,300,17)];
levelName.font = [UIFont fontWithName:@"Chalkduster" size:17.0f];
levelStatus.font = [UIFont fontWithName:@"Chalkduster" size:17.0f];
levelTime.font = [UIFont fontWithName:@"Chalkduster" size:17.0f];
levelHeight.font = [UIFont fontWithName:@"Chalkduster" size:17.0f];
levelScore.font = [UIFont fontWithName:@"Chalkduster" size:17.0f];
levelName.textAlignment = UITextAlignmentCenter;
levelStatus.textAlignment = UITextAlignmentCenter;
levelName.backgroundColor = [UIColor clearColor];
levelStatus.backgroundColor = [UIColor clearColor];
levelTime.backgroundColor = [UIColor clearColor];
levelHeight.backgroundColor = [UIColor clearColor];
levelScore.backgroundColor = [UIColor clearColor];
levelName.textColor = [UIColor whiteColor];
levelStatus.textColor = [UIColor whiteColor];
levelTime.textColor = [UIColor whiteColor];
levelHeight.textColor = [UIColor whiteColor];
levelScore.textColor = [UIColor whiteColor];
levelName.tag = 1;
levelStatus.tag = 2;
levelTime.tag = 3;
levelHeight.tag = 4;
levelScore.tag = 5;
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
[[cell contentView] addSubview:levelName];
[[cell contentView] addSubview:levelStatus];
[[cell contentView] addSubview:levelTime];
[[cell contentView] addSubview:levelHeight];
[[cell contentView] addSubview:levelScore];
[levelName release];
[levelStatus release];
[levelTime release];
[levelHeight release];
[levelScore release];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [self getCellContentView:CellIdentifier];
if([self levelCanBeShown:indexPath.row])
{
GameCard *card = [[[WBManager sharedManager]currentUser]getGameCardForLevel:indexPath.row];
UILabel *levelName = (UILabel *)[cell viewWithTag:1];
UILabel *levelStatus = (UILabel *)[cell viewWithTag:2];
UILabel *levelTime = (UILabel *)[cell viewWithTag:3];
UILabel *levelHeight = (UILabel *)[cell viewWithTag:4];
UILabel *levelScore = (UILabel *)[cell viewWithTag:5];
levelName.text = [self getLevelStringForIntValue:indexPath.row];
levelStatus.text = card.score <= 0 ? @"Incomplete" : @"Complete";
if(card.score != 0)
{
levelScore.text = [NSString stringWithFormat:@"Score: %i",card.score];
levelTime.text = [NSString stringWithFormat:@"Best Time: %i mins %i secs",card.time/60,card.time%60];
levelHeight.text = [NSString stringWithFormat:@"Lowest Height: %i",card.height];
}
else
{
levelScore.text = @"Score: -";
levelTime.text = @"BestTime: -";
levelHeight.text = @"Lowest Height: -";
}
UIImage *screenshot = [[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"WSimg%i",indexPath.row+1] ofType:@"PNG"]];
cell.imageView.image = screenshot;
[screenshot release];
}
else
{
UILabel *levelName = (UILabel *)[cell viewWithTag:1];
UILabel *levelStatus = (UILabel *)[cell viewWithTag:2];
UILabel *levelTime = (UILabel *)[cell viewWithTag:3];
UILabel *levelHeight = (UILabel *)[cell viewWithTag:4];
UILabel *levelScore = (UILabel *)[cell viewWithTag:5];
levelName.text = [self getLevelStringForIntValue:indexPath.row];
levelStatus.text = @"LOCKED";
levelTime.text = @"";
levelHeight.text = @"";
levelScore.text = @"";
UIImage *screenshot = [[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"WSimg%i",indexPath.row+1] ofType:@"PNG"]];
cell.imageView.image = screenshot;
[screenshot release];
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 110;
}