Pergunta

I was following a tutorial: http://www.devx.com/wireless/Article/43374 so I could add alphabet sorting and panning to my UITableView of songs and I have finished coding but this method I have followed slows down the UITableView by filtering arrays and retrieving values in the cellForRowAtIndexPath method. I cant figure out how I can remove the excess coding to increase the speed. All the MPMediaItems are stored in the tableTracks array. Which is initialized in viewDidLoad. And thee musicIndex is an array of the alphabets(first letter of each song). I extended MPMediaItem to include an NSString firstLetter that is the first letter of the song.

Any help speeding it up?

-(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;
}
Foi útil?

Solução

If you are showing separate sections, one for each letter of the alphabet, I would create an array of dictionaries from my data, in viewDidLoad, not here. The dictionaries would have the first letter of the song as the key, and an array of songs as the value. That way, all the filtering and sorting is done up front, rather than in each row as the table is populated.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top