What is the role of selector in UILocalizedIndexedCollation's sectionForObject:(id)object collationStringSelector:(SEL)selector method

為{幸葍}努か 提交于 2019-12-06 12:22:12
Pfitz

In general

With the @selector(title:) you define which method will be called.

in my example it will call

- (void) title:(id)someObject {}

Be carefull with the semicolon at the end! If you have a semicolon at the end you method will have parameters like mine above.

Your code states just @selector(title) and will call a method title without a parameter like this:

- (void)title {}

Specific to UILocalizedIndexCollation

The docs state:

selector
A selector that identifies a method returning an identifying string for object that is used in collation. The method should take no arguments and return an NSString object. For example, this could be a name property on the object.

So i would suggest you implement it like this

self.tableData = [self partitionObjects:objects collationStringSelector:@selector(title)];
 ...
- (NSString *)title {
     NSString *title;
     // some code to fill title with an identifier for your object
     return title;
}
Tyler Chong

Try replace the title with self:

self.tableData = [self partitionObjects:objects collationStringSelector:@selector(self)];

worked for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!