【发布时间】:2013-02-09 20:46:10
【问题描述】:
我正在学习一个教程:http://www.devx.com/wireless/Article/43374 所以我可以在歌曲的 UITableView 中添加字母排序和平移,并且我已经完成了编码,但是我遵循的这种方法通过过滤数组和检索 cellForRowAtIndexPath 方法中的值来减慢 UITableView。 我不知道如何删除多余的编码以提高速度。所有 MPMediaItems 都存储在 tableTracks 数组中。在 viewDidLoad 中初始化。你的 musicIndex 是一个字母数组(每首歌曲的第一个字母)。我扩展了 MPMediaItem 以包含一个 NSString firstLetter,它是歌曲的第一个字母。
有什么加快速度的帮助吗?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//--Create Cell--\\
.........
//--Load Info--\\
NSString *alphabet = [musicIndex objectAtIndex:[indexPath section]];
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"firstLetter beginswith[c] %@", alphabet];
NSArray *songs = [tableTracks filteredArrayUsingPredicate:predicate];
//Needed Object
MPMediaItem *item = [songs objectAtIndex:indexPath.row];
//--Rest of Method--\\
...........
return cell;
}
【问题讨论】:
标签: iphone objective-c xcode uitableview mpmediaitem