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…
I am not sure if it works but you can try this:
If your view controller is not a UITableViewController and it contains a UITableView
[self.tableView removeFromSuperview];then[self.view addSubview];If your view controller is a UITableViewController, you may need to consider to set the first row to contain the image and text. Then, you can handle the event:
tableView:didSelectRowAtIndexPath:and if user click on the first cell, you trigger the method handle the button event