Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show blank UITableViewCells in custom UITableView

I am trying to customize a UITableView. So far, it looks good. But when I use a custom UITableViewCell sub-class, I do not get the blank table cells when there's only 3 cells:

alt text http://img193.imageshack.us/img193/2450/picture1zh.png

Using the default TableView style I can get the repeating blank rows to fill the view (for example, the mail application has this). I tried to set a backgroundColor pattern on the UITableView to the same tile background:

UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"score-cell-bg.png"]];
moneyTableView.backgroundColor = color;

...but the tile starts a bit before the TableView's top, so the tile is off once the actual cell's are done displaying:

alt text http://img707.imageshack.us/img707/8445/picture2jyo.png

How can I customize my tableview but still keep the blank rows if there's less rows than fill a page?

like image 981
typeoneerror Avatar asked Apr 10 '10 17:04

typeoneerror


1 Answers

Did you by chance remove the background color and separator style? If you did, that could be why there are no extra cells. I would think the default UITableView doesn't add more cells really, it just has the separator style to create that illusion and because it has a white background, they look like cells.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

If that's not the case, you could always try adding extra cells that can't be selected:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return ([source count] <= 7) ? 7 : [source count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set all labels to be blank
    if([source count] <= 7 && indexPath.row > [source count]) {
        cell.textLabel.text = @"";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    } else {
        cell.textLabel.text = [source objectAtIndex:indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }

  return cell;
}
like image 50
Garrett Avatar answered Nov 16 '22 00:11

Garrett