【发布时间】:2014-11-07 20:46:21
【问题描述】:
我有一个显示一系列产品的表格视图。每当加载一个空的 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];
}
}
【问题讨论】:
-
你检查 emptyHistoryView.view 的框架了吗?
-
我该怎么做?
-
NSLog(@"%@",NSStringFromCGRect(emptyHistoryView.view.frame));
-
我找回了这个{{0, 0}, {320, 568}}
-
谢谢我想通了
标签: ios uitableview delete-row