我有一个 UITableView ,其中标题视图中有 UISegmentedControl 。它应该与App Store应用程序完全相同:当用户滚动时,标题中的标题滚动屏幕,但 segmentedControl 粘在下navigationBar 。
I have a UITableView, where there is a UISegmentedControl in the header view. It should work exactly like in the App Store app: As the user scrolls, the title in the header scrolls off the screen but the segmentedControl sticks under the navigationBar.
当用户选择一个段时,标题下方的部分应重新加载一个漂亮的 UITableViewRowAnimation 。但是,当我调用 tableView:reloadSections:withRowAnimation:时,标题视图也是动画的,我想阻止它,因为它看起来很糟糕。
When the user selects a segment, the section below the header should be reloaded with a nice UITableViewRowAnimation. However, as I call tableView:reloadSections:withRowAnimation:, the header view is animated as well, which I want to prevent, because it looks terrible.
这是我的代码:
- (void)selectedSegmentIndexChanged:(UISegmentedControl *)sender { int index = sender.selectedSegmentIndex; if (index < self.oldIndex) { [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft]; } else if (index > self.oldIndex) { [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight]; } self.oldIndex = index; }任何人都知道如何重新加载标题下方的部分而不重新加载标题本身?
Anyone has an idea how to reload the section below the header without reloading the header itself?
推荐答案也许你应该试试
[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationLeft] //or UITableViewRowAnimationRight但是,我不确定,但我认为如果您重新加载的行数比以前少,可能会出现一些错误。
However, I'm not sure but I think it can rise some error in the case where you have less rows to reload than previously.
我认为你可以处理 [tableView beginUpdates] 和 [tableView endUpdates] 来解决您的问题。
I think you could deal with [tableView beginUpdates] and [tableView endUpdates] to solve your problem.
例如,您要显示2个数据阵列。我们将它们命名为 oldArray 和 newArray 。 你可以做什么的样本:
For example, you have 2 arrays of data to display. Let name them oldArray and newArray. A sample of how what you could do :
- (void)selectedSegmentIndexChanged:(UISegmentedControl *)sender { [self.tableView setDataSource: newArray]; int nbRowToDelete = [oldArray count]; int nbRowToInsert = [newArray count]; NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init]; for (NSInteger i = 0; i < nbRowToInsert; i++) { [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]]; } NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init]; for (NSInteger i = 0; i < nbRowToDelete; i++) { [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:section]]; } [self.tableView beginUpdates]; [self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationLeft]; [self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationRight]; [self.tableView endUpdates]; }更多推荐
重新加载部分而不重新加载部分标题
发布评论