【发布时间】:2015-08-02 16:16:27
【问题描述】:
我需要在使用 UILocalizedIndexedCollation 时动态设置选择器 在我的应用程序中,我有以下代码:
UILocalizedIndexedCollation *indexedCollation=[UILocalizedIndexedCollation currentCollation];
for (MyObject *theObject in objects)
{
NSInteger section;
section=[indexedCollation sectionForObject:theObject collationStringSelector:@selector(mainTitle)];
theObject.section=(int)section;
}
mainTitle 是 myObject 中的众多属性之一。 但是,我希望选择器可以使用任何字符串。我遵循了这个网站的提示: What is the role of selector in UILocalizedIndexedCollation's sectionForObject:(id)object collationStringSelector:(SEL)selector method,并介绍了以下内容:
-(NSString*)myString
{
NSString* myString;
myString = // whatever code to set new string belonging to myObject
return myString;
}
section=[indexedCollation sectionForObject:theObject collationStringSelector:@selector(myString)];
这导致崩溃并出现错误:[MyObject myString]: unrecognized selector sent to instance ...
添加动态选择器的正确方法是什么?
【问题讨论】:
标签: ios objective-c uilocalizedcollation