2013年09月22日

データのソート

今日は少しデータのソートで悩んでしまったので、メモです。
自分のソースを貼付けてるだけなので、他の人には参考にならないと思いますが。すいません。


- (IBAction)setSendList:(id)sender{
strSelectedIDs = nil;
NSArray *sortedArray = [[NSArray alloc]initWithArray:[friendsDatas sortedArrayUsingFunction:compareInfo context:NULL]];
for (int i=0; i<[sortedArray count]; i++) {
DataFriends *bookData = (DataFriends *)[sortedArray objectAtIndex:i];
if (bookData.intDoSend==1) {
if (strSelectedIDs != nil) {
[strSelectedIDs appendString:@","];
}
[strSelectedIDs appendString:[NSString stringWithFormat:@"%d",bookData.primaryKey]];
}
}
[self.delegate SelectFriendViewControllerDidOK:self];
}

NSInteger compareInfo(id aInfo1, id aInfo2, void *context)
{
int dpercent1 = ((DataFriends*) aInfo1).primaryKey;
int dpercent2 = ((DataFriends*) aInfo2).primaryKey;

if (dpercent1 < dpercent2)
return NSOrderedDescending;
else if (dpercent1 > dpercent2)
return NSOrderedAscending;
else
return NSOrderedSame;
}
プロフィール
けん
カテゴリ
VB関係 (4)
iOS関係 (7)
SQL関係 (1)
< 2013年09>
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
QRコード
QRCODE
アクセスカウンタ
読者登録
メールアドレスを入力して登録する事で、このブログの新着エントリーをメールでお届けいたします。解除は→こちら
現在の読者数 0人
人気の楽園ブログ
楽園ブログ