UA-17470720-3

Jump to content


Photo
- - - - -

How to implement tableView:sectionForSectionIndexTitle:atIndex:


  • Please log in to reply
3 replies to this topic

#1 Joseph Galbraith

Joseph Galbraith

    Starting Out

  • STV Lite
  • Pip
  • 6 posts
Reputation: 3
Good

Posted 22 July 2013 - 04:19 PM

I want the section index titles to include A-Z, even when I don't have sections A-Z (like contacts where you have the full index even if you don't have a contact for a particular 

 

I presume I could do this normally by implementing:

tableView:sectionForSectionIndexTitle:atIndex:
 
to return the nearest "real" section for any items in the index that don't actually have a section.
 
How can I implement this for STV?
 
I'm using an SCArrayOfObjectsModel, and I've implemented modelActions.sectionHeaderTitleForItem to get sections for each item.
 
Thanks,
 
Joseph


#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 24 July 2013 - 01:43 PM

Hi Joseph,

 

I believe you're referring to the SCTableViewModel sectionIndexTitles property.

 

myArrayOfObjectsModel.sectionIndexTitles = @[@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"];

 

Hope this helps.



#3 Joseph Galbraith

Joseph Galbraith

    Starting Out

  • STV Lite
  • Pip
  • 6 posts
Reputation: 3
Good

Posted 24 July 2013 - 02:24 PM

I did try that.  It doesn't quite work correctly (and you can see this behavior in the core data sample app.)

 

In the core data sample application, create the following people:

Abby, Brian, Carry, Daphne, Isaac, Joseph, Kelly, Larry, Mariah, Nancy, Perry, Randy, Sam, Terry, Verra

 

Now, click / tap each letter in the index. A, B, C, D work correctly. E takes you to the "I" section;

not unreasonable since that is the next existing section after E that exists. F takes you to the "J"

section, G to the "K" section, H to the "L" section, and I to the "M" section, which is dead wrong as

there is an "I" section.

 

By implementing the tableView:sectionForSectionIndexTitle:atIndex:, I presume I could tell the table view controller that the sectionIndex at index 8 (the "I" sectionIndex") should map to the Section index 4 (section for I contain "Isaac")  So the question is how can I hook into STV to tell it that the sectionIndex index != to the section index?

 

I'd love it if STV just got this right.  I'm not sure how hard that would be in the general case... especially in view of internationalization and localization challenges.

 

Thanks,

 

Joseph

 

PS. Just in case it wasn't clear, tableView:sectionForSectionIndexTitle:atIndex: is from UITableViewDataSource, and the apple documentation says the following:

 

tableView:sectionForSectionIndexTitle:atIndex:

Asks the data source to return the index of the section having the given title and section title index.

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

The table-view object requesting this information.

title

The title as displayed in the section index of tableView.

index

An index number identifying a section title in the array returned by sectionIndexTitlesForTableView:.

Return Value

An index number identifying a section.

Discussion

This method is passed the index number and title of an entry in the section index list and should return the index of the referenced section. To be clear, there are two index numbers in play here: an index to an section index title in the array returned by sectionIndexTitlesForTableView:, and an index to a section of the table view; the former is passed in, and the latter is returned. You implement this method only for table views with a section index list—which can only be table views created in the plain style (UITableViewStylePlain). Note that the array of section titles returned by sectionIndexTitlesForTableView:can have fewer items than the actual number of sections in the table view.

 


Edited by galbraithjoseph@gmail.com, 24 July 2013 - 02:33 PM.


#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 15 May 2015 - 02:00 PM

Hi Joseph,

 

I really apologize for missing your post earlier. A solution to this has been posted here: http://sensiblecocoa...elp/#entry12346






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users