iOS 7下的UITableView部分索引相关崩溃

use*_*394 9 iphone objective-c uitableview ios7

我有一个表格视图的简单部分索引,第一次看起来很好,但如果发生某些类型的交互强制重新绘制部分索引,则会崩溃:

  1. 通过点击其中一个单元格来推动视图控制器
  2. 点击表格视图标题中的搜索栏或以其他方式使其成为第一响应者
  3. 转到信息屏幕,然后返回到具有该表视图的视图控制器.

如果我注释掉段索引(通过在sectionIndexTitlesForTableView中返回nil而不是"[self.collat​​ion sectionIndexTitles]"),它就可以了.

它只发生在iOS 7下(因为测试版并没有在7.0.1版本中修复)而且我总是得到以下与CoreText /动画/过渡相关的堆栈跟踪:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000001f0
Triggered by Thread:  0

Thread 0 Crashed:
0   CoreText                        0x31403312 TComponentFont::GetMinSideBearing(CGAffineTransform const&, bool) const + 10
1   CoreText                        0x313f3ada TRun::GetLeftHangersGlyphCountAndWidth(long, unsigned long, TCharStream const&) const + 322
2   CoreText                        0x313f394c TLine::GetLeftHangersGlyphCountAndWidth(unsigned long const*) const + 148
3   CoreText                        0x314025d8 TLine::GetBounds(unsigned long) const + 496
4   CoreText                        0x314023ca CTLineGetBoundsWithOptions + 10
5   UIKit                           0x333641f6 -[UITableViewIndex _cacheAndMeasureTitles] + 758
6   UIKit                           0x33364b8e -[UITableViewIndex sizeThatFits:] + 198
7   UIKit                           0x332f0d62 -[UITableView _updateIndexFrameSuppressingChangeNotification:] + 546
8   UIKit                           0x332f6fe0 -[UITableView setContentInset:] + 268
9   UIKit                           0x332cbaf8 -[UIViewController _setNavigationControllerContentInsetAdjustment:] + 436
10  UIKit                           0x332e432e -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 458
11  UIKit                           0x333af438 __49-[UINavigationController _startCustomTransition:]_block_invoke + 156
12  UIKit                           0x333340b0 -[_UIViewControllerTransitionContext completeTransition:] + 72
13  UIKit                           0x333f4402 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke105 + 450
14  UIKit                           0x332557c6 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 282
15  UIKit                           0x33255412 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 174
16  UIKit                           0x3325532a -[UIViewAnimationState animationDidStop:finished:] + 66
17  QuartzCore                      0x32eadd94 CA::Layer::run_animation_callbacks(void*) + 228
18  libdispatch.dylib               0x3b21cd64 _dispatch_client_callout + 20
19  libdispatch.dylib               0x3b2237bc _dispatch_main_queue_callback_4CF$VARIANT$mp + 264
20  CoreFoundation                  0x30d1480c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
21  CoreFoundation                  0x30d130e0 __CFRunLoopRun + 1296
22  CoreFoundation                  0x30c7dcd2 CFRunLoopRunSpecific + 518
23  CoreFoundation                  0x30c7dab6 CFRunLoopRunInMode + 102
24  GraphicsServices                0x356c32d6 GSEventRunModal + 134
25  UIKit                           0x3328211c UIApplicationMain + 1132
Run Code Online (Sandbox Code Playgroud)

我几乎排除了与内存相关的问题,因为它发生在空表和6000个单元格中.

这是节索引的代码:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{
    // Don't show section titles when a search is in progress
    if (isFilterInProgress && [self.searchDisplayController isActive]) {
        return nil;
    }

    return  [[self.collation sectionIndexTitles] objectAtIndex:section];
}


- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView 
{
    if(tableView == self.resultsTable){

        // Don't show section titles when a search is in progress
        if (isFilterInProgress && [self.searchDisplayController isActive]) {
            return nil;
        }

        // Don't show section titles when there are filtered results
        if ([self.filteredListContent count] > 0)
            return nil;

        // iOS7 temporary fix for crashes (ICM-9)
        if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){

            // Crashes under iOS 7 when displayed for a second time!
            return [self.collation sectionIndexTitles];
            //return nil;

        }else{

            return [self.collation sectionIndexTitles];  

        }

    }else return nil;
}


- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index 
{

    // Return correct section
    if(tableView == self.resultsTable){
        return [self.collation sectionForSectionIndexTitleAtIndex:index];
    }else{
        return 0;
    }   
}
Run Code Online (Sandbox Code Playgroud)

是否有其他人有类似的问题或任何其他与部分索引相关的问题?我知道表视图部分索引和编辑单元格上的删除按钮有一些布局问题,但我不确定是否已经修复了这些问题.我怀疑这只是iOS 7中的一个错误?

use*_*394 3

在我的例子中,这个问题似乎与后台线程上尝试从后台线程进行 reloadData 调用有关。我猜视图中的数据与索引或类似的内容不一致。

奇怪的是,它以 CoreText 库(如上面的堆栈跟踪中所示)和 iOS 7 中看到的形式表现出来。

当在主队列上调度调用以重新加载表视图的数据时,重新加载性能得到改善,我可以再次使用部分索引。从那以后我就再没有发生过那次车祸。

看看这样做是否可以解决您的问题。