重新加载部分而不重新加载部分标题

编程入门 行业动态 更新时间:2024-10-26 14:36:47
本文介绍了重新加载部分而不重新加载部分标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 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]; }

更多推荐

重新加载部分而不重新加载部分标题

本文发布于:2023-10-12 21:01:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485884.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   而不   标题

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!