The iOS application I'm working on is based on a time sheet, and one of the tabs is the UITableViewController.
The thing is, when I open this tab with an empty data source (for some reason), I would like to add another view with some kind of message / image instead of the empty view that I get with tableviewcontroller.
I tried something like this:
- (void)viewWillAppear:(BOOL)animated { if ([myData count] == 0) { if (!emptyView) { emptyView = [[UIView alloc] initWithFrame:self.view.frame]; UILabel *emptyMsg = [[UILabel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height / 2, self.view.frame.size.width, 20)]; emptyMsg.text = @"This is Empty !"; emptyMsg.textAlignment = UITextAlignmentCenter; [emptyView addSubview:emptyMsg]; } [self.view insertSubview:emptyView atIndex:0]; } else { if (emptyView != nil) { [emptyView removeFromSuperview]; emptyView = nil; } [self.tableView reloadData]; [super viewWillAppear:animated]; } }
With an empty view defined as iVar in the view controller.
But it does not work as expected, and I can not find the reason: /
Can any of you look at him and give me the right way to commit this behavior?
Thanks,
source share