4
ABPersonGetSortOrdering()の結果に応じて、姓または名でUILocalizedIndexCollationを並べ替える必要があります。@セレクタを動的に渡す
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