iPhone: Add background button to view when UITableView has no cells

Posted by Nic Hubbard on Stack Overflow See other posts from Stack Overflow or by Nic Hubbard
Published on 2010-06-06T04:13:56Z Indexed on 2010/06/06 4:22 UTC
Read the original article Hit count: 247

I have a UITableViewController, when there is no data to populate the UITableView, I want to add a button, which uses an image. So, rather than the user seeing a tableview with no records, they will see an image that says, "No records have been added, Tap to add one", then they click and we create a new one.

I assumed I would just hide the UITableView, then create the button, but I never see the button. Here I am using:

if ([[fetchedResultsController sections] count] == 0) {
        self.tableView.hidden = YES;
        // Create button w/ image
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake(0, 0, 100, 50);
        [btn setImage:[UIImage imageNamed:@"no-rides.png"] forState:UIControlStateNormal];
        [self.view addSubview:btn];
    }

Ideas on why I would never see the button? When I show this view, it seems to have a transparent background for a second, then changes white...

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk