【发布时间】:2015-11-16 22:47:20
【问题描述】:
我有一个嵌入在 containerview 中的 Tableview。加载时表格视图有一个部分,用户可以将单元格标记为已完成,这会将它们移动到已完成的部分。我的问题是在我将一个单元格移动到完成部分之后,如果我改变方向,单元格会回到原来的位置,完成部分是空的。它会改变方向并调整单元格内的所有标签和图像的大小。如何让表格视图改变两个部分中的数据的方向? 这就是我加载嵌入式 tableviewcontroller 的方式,
- (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];
【问题讨论】:
-
有什么代码可以给我们看看(可能是表格的数据源)?
-
我使用embed segue嵌入tableview控制器,PickTasksTableViewController *viewController = segue.destinationViewController;
-
表格从哪里获取数据(例如,写入单元格中的文本)?
-
我从 prepareForSegue:sender 传递它。它是一个数组,viewcontroller.tasks=self.tasks;
-
那么,当单元格被移动时,您的数据源 (
self.tasks) 会发生变化吗?当方向改变时,表格会重新加载其数据。
标签: ios objective-c iphone uitableview uicontainerview