UILocalizedIndexedCollat​​ion与自定义部分

时间:2013-11-18 10:09:14

标签: ios objective-c uitableview sorting

假设我有一个叫做动物的物体,有2个叫做物种和品种的田地。

我有一些物种,其中物种是海豚,有些物种是狗。

我希望各个部分按物种划分,因此我会有狗和海豚的部分和部分索引标题中的D(右侧的字母滑块以快速导航)会因为g来在字母表中我之前。

我目前根据物种将我的对象分类为部分,但默认情况下,UILocalizedIndexedCollat​​ion已将狗和海豚对象分类为“D”部分,而海豚和狗的种类在该部分内混杂在一起(尽管按字母顺序排序)。我将如何实现我想要的功能?感谢。

1 个答案:

答案 0 :(得分:2)

经过一些研究,结果证明我可以实现我自己的版本uilocalizedindexedcollat​​ion来完成我想要的事情。

我只需要拥有这些基本的属性和功能,我可以让它做任何我想做的事情。

// Provides the list of section titles used to group results (e.g. A-Z,# in US/English)
@property(nonatomic, readonly) NSArray *sectionTitles;

// Provides the list of index titles used to quickly jump to particular sections
@property(nonatomic, readonly) NSArray *sectionIndexTitles;

// Specifies the section that should be scrolled to for the title at the given index.
// This method allows you to map between a given item in the index
// and a given section where there isn't a one-to-one mapping.
- (NSInteger)sectionForSectionIndexTitleAtIndex:(NSInteger)indexTitleIndex;

// Returns the index of the section that will contain the object.
// selector must not take any arguments and return an NSString.
- (NSInteger)sectionForObject:(id)object collationStringSelector:(SEL)selector;

// Used for sorting objects within the same section.
// selector must not take any arguments and return an NSString.
// In the process of sorting the array, each object may receive
// selector multiple times, so this method should be fast.
- (NSArray *)sortedArrayFromArray:(NSArray *)array collationStringSelector:(SEL)selector;