I have a simple section index for a table view that appears fine for the first time but then crashes if certain kinds of interaction happens that force a redraw of the section index, either by:
If I comment out the section index (by returning nil in sectionIndexTitlesForTableView instead of the "[self.collation sectionIndexTitles]"), it works just fine.
It ONLY happens under iOS 7 (since the betas and it's not fixed in the 7.0.1 release) and I always get the following stack trace related to CoreText / animations / transitions:
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
I've pretty much ruled out it's memory-related because it happens with an empty table as well as 6000 cells.
This is the code for the section index:
- (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;
}
}
Is anyone else having similar issues or any other related to section indices? I knew there were some layouting issues with the table view section index together with delete buttons on editing cells but I'm not sure if those have been fixed either. I suspect it's just a bug in iOS 7?
I have been experiencing this exact issue. I solved this after days of frustration by using a 3rd party section index view and not using the native sectionIndexTitlesForTableView
. Check out CMIndexBar. Super easy, got it up an running in about 5 minutes. Easily customizable. This is what I will be using until Apple addresses this bug and I highly recommend it if you are experiencing this crash.
The issue seemed to have to do with a reloadData call being attempted from a background thread on a background thread, in my case. I guess the data in the view was inconsistent with the index or something like that.
Weird how it manifests itself in the form seen in the CoreText library (as seen in the stack trace above) and on iOS 7 only.
When dispatching the call on the main queue to reload the table view's data, reloading performance improved and I could use the section index again. I haven't had that crash since.
See if doing that fixes it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With