子類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
希望這有助於!
我想你還需要禁用滾動功能。 –