- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有展开/折叠部分的表格 View 的应用程序,遵循 Apple 的 Table View Animations & Gestures sample app 中的示例。 .当一个项目被添加到一个关闭的部分时我遇到了问题:之后,该部分不再打开,当我尝试打开然后关闭它时出现异常。
我已经将其追溯到打开/关闭方法中的一些奇怪行为:
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)section {
if (![[sectionHeaderArray objectAtIndex:section] isOpen]) {
[[sectionHeaderArray objectAtIndex:section] setIsOpen:YES];
NSLog(@"self.tableView: %@", self.tableView);
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
NSInteger countOfRowsToInsert = [sectionInfo numberOfObjects];
NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToInsert; i++) {
[indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]];
}
// Apply the updates.
[self.tableView beginUpdates];
NSLog(@"Count of rows to insert: %d", [indexPathsToInsert count]);
NSLog(@"Rows before insert: %d", [self.tableView numberOfRowsInSection:section]);
[self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationTop];
NSLog(@"Rows after insert: %d", [self.tableView numberOfRowsInSection:section]);
[self.tableView endUpdates];
}
}
-(void)sectionHeaderView:(SectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)section {
if ([[sectionHeaderArray objectAtIndex:section] isOpen]) {
[[sectionHeaderArray objectAtIndex:section] setIsOpen:NO];
NSInteger countOfRowsToDelete = [self.tableView numberOfRowsInSection:section];
if (countOfRowsToDelete > 0) {
NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
for (NSInteger i = 0; i < countOfRowsToDelete; i++) {
[indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:section]];
}
[self.tableView beginUpdates];
NSLog(@"Count of rows to delete: %d", [indexPathsToDelete count]);
NSLog(@"Rows before delete: %d", [self.tableView numberOfRowsInSection:section]);
[self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationTop];
NSLog(@"Rows after delete: %d", [self.tableView numberOfRowsInSection:section]);
}
[self.tableView endUpdates];
}
}
日志消息显示,在打开(插入行)时,插入了 >0 行,但该部分的行数仍为 0:
2012-03-31 13:36:17.454 QuickList7[5523:fb03] Count of rows to insert: 3
2012-03-31 13:36:17.454 QuickList7[5523:fb03] Rows before insert: 0
2012-03-31 13:36:17.454 QuickList7[5523:fb03] Rows after insert: 0
这在表和数据源之间设置了不一致的状态,然后当我尝试“折叠”该部分时,出现以下异常:
2012-03-31 13:48:35.783 QuickList7[5523:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid table view update. The application has requested an update to the table view that is inconsistent with the state provided by the data source.'
我怎样才能插入 3 行,最后仍然是 0 行?
谢谢,
萨沙
最佳答案
我找到问题了!它实际上在 fetchedResultsController 的更改处理程序中。它正在响应对关闭部分的更改,这使表处于错误状态,并且与数据源不同步。所以我为每个更新添加了一个检查,以仅在包含部分打开时插入/删除/更新行。
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
UITableView *tv = self.tView;
switch(type) {
case NSFetchedResultsChangeInsert:
if ([[sectionHeaderArray objectAtIndex:newIndexPath.section] isOpen]) {
[tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
break;
case NSFetchedResultsChangeDelete:
if ([[sectionHeaderArray objectAtIndex:indexPath.section] isOpen]) {
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
break;
case NSFetchedResultsChangeUpdate:
if ([[sectionHeaderArray objectAtIndex:indexPath.section] isOpen]) {
[self configureCell:[tv cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
}
break;
case NSFetchedResultsChangeMove:
if ([[sectionHeaderArray objectAtIndex:indexPath.section] isOpen]) {
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
if ([[sectionHeaderArray objectAtIndex:newIndexPath.section] isOpen]) {
[tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
}
break;
}
}
关于ios - 未插入 UITable 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9958234/
我有两个 UITable,一个在另一个之上。用户可以点击并将元素从顶部表格拖动到底部。当元素被拖动到底部表格上时,它就会消失。 当表格并排时,不会出现此问题。 线索/症状可能是;当您滚动顶部表格时,如
谁能指导我如何做这样的事情: 我设法完成了第一个和最后一个屏幕,我需要在它们之间插入另一个屏幕。 有什么教程可以学习吗? 非常感谢:) 最佳答案 使用 uitableview 创建一个 uinavig
我有一个链接到我的 viewController 的 UITable,它具有 DataSource 和 Delegate 的扩展。然而,当我查看 View Controller 上的连接时,它们没有链
我的应用程序包含 UITableView 并显示来自 SQLite 的数据。我想在用户滚动 tableview 时始终显示 UITableView 的标题。如何实现它? 最佳答案 您必须将 View
我的应用程序因内存问题(使用太多内存)而崩溃。当我从 TableView 打开足够多的对象时,就会发生这种情况。我已经在互联网上搜索了这个问题,我可以看出这可能是因为内存从未被释放过。但我该如何释放它
我想知道如何使 UITable 具有列。或者,是否有更好的方法来创建一个看起来像网格的实际表格。我想要 3 列。我该怎么做? 最佳答案 UITableView 不支持多列。但是,如果您创建自己的自定义
我创建了一个 matfile,其中存储了不断被用户行为覆盖的数据。这发生在函数“test()”中。 n=1 while n < 5 myVal = double(Test704(1, 780,
我一直在搜索并尝试让我的 UITableView 节标题允许多行文本,但我无法让它工作。这是它显示的内容: 但文字是:埃弗顿足球俱乐部的主场 Jersey 是什么颜色? 我目前正在尝试的是: func
我正在构建一个简单的 iOS 应用程序,它有两个 UITableViewController,我用它来创建一个用于日期导航的水平表 (ScrollingDateViewController) 和第二个
我有一个简单的 UITable 实现和一个名为 fruits 的数组。摘自this例子。唯一的区别是我为 UITable 使用 UIViewController 而不是 UITableViewCont
我有一个名为 gatherData 的函数,它遍历 Firebase 数据库中的目录和数据。因为它使用异步函数,所以返回数据并不是一个明显的选择。我使用以前问题的其他解决方案来确定我需要一个回调系统。
我有一个 UITableViewController,它有两个部分。第一部分显示一个带有居中文本的单元格,内容为添加新幻灯片。第二部分显示当前幻灯片。 当用户点击添加新幻灯片单元格时,新的UITabl
如何在 UITable 中制作用于移动行的自定义按钮? 我希望它是透明的。 (而不是这个:) 另一件事是,当单元格移动时,它有阴影。是否可以删除它? 最佳答案 试试这个... 您必须通过继承 UITa
我使用以下代码将图像添加到 UITableview。我想不通的是如何让背景图像随表格滚动(不是每个单元格中的图像,而是 UITable 后面的大图像)。我需要背景图像可滚动并与 UITable 滚动同
我想更改 UITableView 部分标题的颜色。 最佳答案 使用以下代码作为您的答案 -(UIView *)tableView:(UITableView *)tableView viewForHea
我正在尝试在 UITableViewController 内的每个 UITable 单元格中创建一个按钮。我在我的 Storyboard中的单元格中放置了一个按钮,但是当我尝试在我的 swift 文件
出于性能原因,我在 Matlab 中使用旧版本的 uitable。我正在尝试更改表格标题的单元格边框颜色。目前,两个列标题单元格彼此无法区分。我尝试了以下方法: 自定义列渲染器但仍然无法更改表格标题边
我已经实现了这个滑动删除但是作为一个清除按钮将 uitableviewcells 文本标签重置为空...当这个方法被执行时它完美地工作..但是当用户在滑动清除后触摸同一个单元格时没有任何反应... 然
我有一个带有展开/折叠部分的表格 View 的应用程序,遵循 Apple 的 Table View Animations & Gestures sample app 中的示例。 .当一个项目被添加到一
我有一张 table ,我正在为其做一些特殊的加载。用户开始滚动到底部。当用户滚动到顶部附近时,我通过 ScrollView 委托(delegate)方法检测到这一点,我快速加载一些额外的内容,并填充
我是一名优秀的程序员,十分优秀!