4
根据ABPersonGetSortOrdering()的结果,我想按名字或姓氏对UILocalizedIndexCollation进行排序。动态传递@selector
我在切换用于collationStringSelector参数的@selector时遇到问题。
这将会是很容易只写这个冗长:
NSArray *sortedSubarray; if (ABPersonGetSortOrdering() == 0) { sortedSubarray = [collation sortedArrayFromArray:[sections objectAtIndex:section] collationStringSelector:@selector(fname)]; } else { sortedSubarray = [collation sortedArrayFromArray:[sections objectAtIndex:section] collationStringSelector:@selector(lname)]; }
我已经试过这样的事情,没有运气:
SEL sorter = ABPersonGetSortOrdering() == 0 ? NSSelectorFromString(@"fname") : NSSelectorFromString(@"lname"); sortedSubarray = [collation sortedArrayFromArray:[sections objectAtIndex:section] collationStringSelector:@selector(sorter)];
我已经尝试了其他的想法,似乎没有任何工作。
有没有更好的方式来动态地传递选择器名称?
真棒!我尽力不要问这个问题......至少我接近了!感谢您的快速回复。 – djibouti33 2011-03-17 07:06:37