容器视图中嵌入的表视图在方向更改时重置数据



我在容器视图中嵌入了一个表视图。表视图在加载时有一个部分,用户可以将单元格标记为已完成,这将把它们移到已完成的部分。我的问题是,在我将一个单元格移动到已完成的部分之后,如果我改变方向,单元格会回到其原始位置,而已完成的区域是空的。它会更改方向并调整单元格内所有标签和图像的大小。如何使用两个部分中的数据更改表视图的方向?这就是我加载嵌入式表视图控制器的方式

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if([segue.identifier isEqualToString:@"embedPickListSegue"]) {
    TasksTableViewController *viewController = segue.destinationViewController;
//this array is used to create the tableview
viewController.tasks = self.tasks;
}

然后在TasksTableViewController中,当用户选择完成时,

[self.tasks removeObject:task];
NSIndexPath *removeIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
[self.complete insertObject:task atIndex:0];
NSIndexPath *insertIndexPath = [NSIndexPath indexPathForRow:0 inSection:1];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[removeIndexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:@[insertIndexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];

我发现了这个问题。我对可用的和已完成的任务使用全局数组来加载表,它解决了这个问题。我使用的两个数组都在方向更改时被重新初始化。

最新更新