我想對從MPMediaQuery
生成的UITableView
進行基本排序。Sorting UITableView
我想要的只是一個基本的歌曲列表,將歌曲分爲A,B,C,D等部分。不應該很難,但是我試過的每個教程都會結束完全給我這些結果。
任何幫助將是美好的。這是我的基本代碼。我知道這是不是甚至接近有我想要的成就,但我想它會更容易爲經驗豐富的開發人員,以幫助我從這個角度再惹我在
如何生成我的數據:
MPMediaQuery *musicLibraryQuery = [[MPMediaQuery alloc] init];
NSArray *musicLibraryArray = [musicLibraryQuery items];
songLibrary = [NSMutableArray arrayWithArray:musicLibraryArray];
這些都是我的UITableView方法:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [songLibrary count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SongCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
MPMediaItem *song = [[songLibrary objectAtIndex:[indexPath row]] representativeItem];
cell.textLabel.text = [song valueForProperty:MPMediaItemPropertyTitle];
return cell;
}
請試試這個 - > http://stackoverflow.com/questions/5820979/objective-c-sort-an-array-of-串 – Vinodh