Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:18:24+00:00 2026-05-25T18:18:24+00:00

I am displaying a UITableView modally, but it takes about two seconds for it

  • 0

I am displaying a UITableView modally, but it takes about two seconds for it to appear, below is the code that is holding up the transition.

ModalViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // get all songs from iTunes library
    MPMediaQuery *songQuery = [MPMediaQuery songsQuery];
    // put the songs into an array 
    self.songsArray = [songQuery items];
    // create a sectioned array where songs are sectioned by title
    self.sectionedSongsArray = [self partitionObjects:self.songsArray collationStringSelector:@selector(title)];
}

- (NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
    UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];
    NSInteger sectionCount = [[collation sectionTitles] count];
    NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
    for(int i = 0; i < sectionCount; i++)
    {
        [unsortedSections addObject:[NSMutableArray array]];
    }
    for (id object in array)
    {
        NSInteger index = [collation sectionForObject:object collationStringSelector:selector];
        [[unsortedSections objectAtIndex:index] addObject:object];
    }
    NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
    for (NSMutableArray *section in unsortedSections)
    {
        [sections addObject:[collation sortedArrayFromArray:section collationStringSelector:selector]];
    }
    return sections;
}

The above code works fine, but its slow to load the modal view first time, is there a better way to do this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:18:25+00:00Added an answer on May 25, 2026 at 6:18 pm

    Yeah: don’t do it in -viewDidLoad. A better place would be in the view controller’s -init or -initWithNibNamed:bundle: or whatever, and in the background. Example:

    - (id)init
    {
        self = [super init];
        if(self)
        {
            // ...
    
            dispatch_async(dispatch_get_global_queue(DISPATCH_PRIORITY_DEFAULT, 0), ^{
                // since it's not on the main thread, you need to create your own autorelease pool to prevent leaks
                NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
                MPMediaQuery *songQuery = [MPMediaQuery songsQuery];
                self.songsArray = [songQuery items];            
                self.sectionedSongsArray = [self partitionObjects:self.songsArray collationStringSelector:@selector(title)];
    
                // UI calls have to be on the main thread, so we go back to that here
                dispatch_async(dispatch_get_main_queue(), ^{
                    if([self isViewLoaded])
                    {
                        [self.tableView reloadData];
                    }
                });
    
                // this releases any objects that got autoreleased earlier in the block
                [pool release];
            });
        }
    
        return self;
    }
    

    Your -tableView:numberOfRowsInSection: method should of course now check whether sectionedSongsArray is non-nil and in that case return 0 (or 1 if you want to display a “loading” cell, which you probably should).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView that can be edited. I am displaying cells as such:
i have two views 1st one is displaying list (uitableview used), user will select
i am displaying array of data in a table view. my code for that
I want to display custom cells, but my code is only displaying one custom
I have a UITableView where I am displaying a list of data. I would
I am displaying a texture that I want to manipulate without out affecting the
I have a UITableView that is populated with cells of a variable height. I
I have a very simple UITableView that has 3 sections, and 3 rows per
I have a UITableView displaying a list of Cities. I want to separate them
I am displaying iAd's in the headerView of a UITableView. When the user scrolls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.