我有一个显示一系列产品的tableview。每当空的tableview加载时,我会显示一个标签,要求用户搜索产品。
当用户从此视图中删除所有产品时,我希望显示相同的子视图。我解雇了该方法,但在用户删除最后一个产品后,该视图将不会显示。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
MSAProduct* product = _history[indexPath.row];
[_history removeObjectAtIndex:indexPath.row];
[_db deleteFromHistory:product.model];
_history = [_db getHistory];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self checkForEmptyHistory];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
-(void)checkForEmptyHistory{
if (_history.count == 0) {
emptyHistoryView = [self.storyboard instantiateViewControllerWithIdentifier:@"MSAEmptyHistoryViewController"];
[self.myPageSubView addSubview:emptyHistoryView.view];
[self.view bringSubviewToFront:myPageSubView];
NSLog(@"Sub View should be visible");
}
else if (_history.count >0)
{
[self.tableView setHidden:NO];
[myPageSubView removeFromSuperview];
}
}
答案 0 :(得分:0)
而不是添加和删除子视图。我只需添加子视图并切换子视图的隐藏属性。