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;
}


同じカテゴリー(iOS関係)の記事
 cellForRowAtIndexPathでセルがつくれない (2013-11-28 00:10)
 xCodeで今日の0時のNSDateを取得 (2013-08-24 12:05)
 iPhoneアプリでviewがずれる現象 (2013-06-15 11:40)
 アップルのアプリ内課金の審査 (2013-04-25 08:26)
 コンパイル時のエラー (2013-04-20 12:20)
 手書き文字認識 (2013-04-19 11:59)
※このブログではブログの持ち主が承認した後、コメントが反映される設定です。
上の画像に書かれている文字を入力して下さい
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。
プロフィール
けん
カテゴリ
VB関係 (4)
iOS関係 (7)
SQL関係 (1)
< 2025年05月 >
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 31
QRコード
QRCODE
アクセスカウンタ
読者登録
メールアドレスを入力して登録する事で、このブログの新着エントリーをメールでお届けいたします。解除は→こちら
現在の読者数 0人
人気の楽園ブログ
楽園ブログ