Subclass UITableViewController
,然后在-viewDidAppear:
或其他类似的适当位置,检查表中的单元格数是否为零。如果是这样,请添加此叠加层;如果没有,请确保删除覆盖。下面的示例代码:
@interface MyTableViewController : UITableViewController
...
@property (nonatomic, weak) UIImageView *informativeOverlayImageView;
...
@end
@implementation MyTableViewController
...
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Just for an example - you'll have your own logic for determining if there will be zero rows.
if (self.myDataModel.items.count == 0 &&
!self.informativeOverlayImageView.superview)
{
if (!self.informativeOverlayImageView)
{
self.informativeOverlayImageView = [[UIImageView alloc] initwithImage:[UIImage imageNamed:@"someImageName"]];
[self.informativeOverlayImageView sizeToFit];
}
[self.view addSubview:self.informativeOverlayImageView];
}
else if (self.myDataModel.items.count > 0 &&
self.informativeOverlayImageView.superview)
{
[self.informativeOverlayImageView removeFromSuperview];
[self.tableView reloadData]; // Add animations to taste.
}
}
...
@end
希望这可以帮助!