2012-05-02 6 views
0

私のアプリケーションでは、4つのボタンでsc​​rollViewを使用しています。 いずれかのボタンをクリックすると、テーブルが行ごとに動的に表示されます。tableViewCellで昇順に値を整列する

私の問題は、それらを昇順に並べ替えることです。

サンプルコードがこのscrollviewするボタンを追加するためのものである

であるこれは私がのサブクラスである別のクラスのテーブルの行にこの値を追加するために使用される方法であって、1つのクラスにおいて

 browseScrollView.hidden = NO; 
    browseScrollView.frame = CGRectMake(15, 57, 480, 44); 
    [browseScrollView setContentSize:CGSizeMake(600, 40)];   
    firstButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [firstButton setFrame:CGRectMake(5,3,91,37)]; 
    [firstButton setImage:[UIImage imageNamed:@"genres.png"] forState:UIControlStateNormal]; 
    firstButton.tag = 1; 
    [firstButton addTarget:self action:@selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown]; 
    [browseScrollView addSubview:firstButton]; 

    secondButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [secondButton setFrame:CGRectMake(110,3,91,37)]; 
    [secondButton setImage:[UIImage imageNamed:@"artists.png"] forState:UIControlStateNormal]; 
    secondButton.tag = 2; 
    [secondButton addTarget:self action:@selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown]; 
    [browseScrollView addSubview:secondButton]; 

    thirdButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [thirdButton setFrame:CGRectMake(209,3,91,37)]; 
    thirdButton.tag = 3; 
    [thirdButton setImage:[UIImage imageNamed:@"albums.png"] forState:UIControlStateNormal]; 
    [thirdButton addTarget:self action:@selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown]; 
    [browseScrollView addSubview:thirdButton]; 


    fourthButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [fourthButton setFrame:CGRectMake(317,3,91,37)]; 
    fourthButton.tag = 4; 
    [fourthButton setImage:[UIImage imageNamed:@"songs.png"] forState:UIControlStateNormal]; 
    [fourthButton addTarget:self action:@selector(fourthPageSongSelction:) forControlEvents:UIControlEventTouchDown]; 
    [browseScrollView addSubview:fourthButton]; 

    tableView.hidden = NO; 
    tableView.frame = CGRectMake(5, 100, 235, 200); 
    tableView.showsVerticalScrollIndicator = NO; 

れますTableViewCell

-(void) showFourthPageControlValues :(int) currRow :(int)val 
{ 
int value = val; 
TonifyAppDelegate *appDelegate = (TonifyAppDelegate *)[UIApplication sharedApplication].delegate; 

if (value == 1) 
{ 
    genresLabel1.hidden = NO; 
    genresLabel2.hidden = NO; 

    genresButton.hidden = NO; 

    artistLabel1.hidden = YES; 
    artistLabel2.hidden = YES; 
    artistButton.hidden = YES; 

    albumLabel1.hidden = YES; 
    albumLabel2.hidden = YES; 
    albumButton.hidden = YES; 

    songsLabel1.hidden = YES; 
    songsLabel2.hidden = YES; 
    songsButton.hidden = YES; 

    [genresLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"Genre"]]; 
    [genresLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"SongName"]]; 
    [genresButton addTarget:self.delegateController action:@selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside]; 
    genresButton.tag = currRow; 
} 

if (value == 2) 
{ 
    genresLabel1.hidden = YES; 
    genresLabel2.hidden = YES; 
    genresButton.hidden = YES; 

    artistLabel1.hidden = NO; 
    artistLabel2.hidden = NO; 
    artistButton.hidden = NO; 

    albumLabel1.hidden = YES; 
    albumLabel2.hidden = YES; 
    albumButton.hidden = YES; 

    songsLabel1.hidden = YES; 
    songsLabel2.hidden = YES; 
    songsButton.hidden = YES; 

    [artistLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"ArtistName"]]; 
    [artistLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"SongName"]]; 

    [artistButton addTarget:self.delegateController action:@selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside]; 
    artistButton.tag = currRow; 
} 
if (value == 3) 
{ 
    genresLabel1.hidden = YES; 
    genresLabel2.hidden = YES; 
    genresButton.hidden = YES; 

    artistLabel1.hidden = YES; 
    artistLabel2.hidden = YES; 
    artistButton.hidden = YES; 

    albumLabel1.hidden = NO; 
    albumLabel2.hidden = NO; 
    albumButton.hidden = NO; 

    songsLabel1.hidden = YES; 
    songsLabel2.hidden = YES; 
    songsButton.hidden = YES; 

    [albumLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"AlbumName"]]; 
    [albumLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"SongName"]]; 

    [albumButton addTarget:self.delegateController action:@selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside]; 
    albumButton.tag = currRow; 
} 
if (value == 4) 
{ 
    genresLabel1.hidden = YES; 
    genresLabel2.hidden = YES; 
    genresButton.hidden = YES; 

    artistLabel1.hidden = YES; 
    artistLabel2.hidden = YES; 
    artistButton.hidden = YES; 

    albumLabel1.hidden = NO; 
    albumLabel2.hidden = NO; 
    albumButton.hidden = NO; 

    songsLabel1.hidden = NO; 
    songsLabel2.hidden = NO; 
    songsButton.hidden = NO; 

    [songsLabel1 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"SongName"]]; 
    [songsLabel2 setText:[[appDelegate.songsList objectAtIndex:currRow] valueForKey:@"AlbumName"]]; 
    [songsButton addTarget:self.delegateController action:@selector(songTypeSelAction:) forControlEvents:UIControlEventTouchUpInside]; 
    songsButton.tag = currRow; 
} 

}

これはメタでありますOD私はあなたがTI preferable..Thanをしたい場合は、4つのボタンとのtableViewを追加します....新しいビューを取るthis..First行うことができます選択または行

-(void) songTypeSelAction :(id) sender 
{ 
NSLog(@"songTypeSelAction"); 
UIButton *btn = (UIButton *) sender; 
NSLog(@"songTypeSelAction bttn.tag: %d", btn.tag); 
if ([self.delegateController respondsToSelector:@selector(songImageSelAction:)]) 
{ 

} 
} 
+0

実際には –

+0

は動的にtableViewCell(行)に値を追加していますので、その値を並べ替えてtableViewCell(行)に追加します。 –

+0

これは配列をソートする必要があります(データソース) – Mangesh

答えて

2
NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"SongName" ascending:TRUE]; 
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"AlbumName" ascending:TRUE]; 
[appDelegate.songsList sortUsingDescriptors:[NSArray arrayWithObjects:sortDescriptor1,sortDescriptor2, nil]]; 
+0

その作業、ありがとうKuldeep –

0

のために使用しています。この従うより

: - >埋め込みで - 編集ボタンのクリックイベントよりも> ScrollView

は、テーブルを表示し、ショーの時にテーブルビューのデータをリロードすることを忘れないでください。

質問があれば私に尋ねます。

関連する問題