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 8223349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:39:45+00:00 2026-06-07T14:39:45+00:00

I’m building an app that starts off with a UITableView however the first time

  • 0

I’m building an app that starts off with a UITableView however the first time I build and run my app on my phone the UITableView shows up empty. If I stop the run then re-build and run it again all the data shows up. Also If the app is already on my phone it builds and runs fine. It’s just the first initial build and run when it “installs” the app on my phone that leaves the UITableView empty. I’m curious if this is going to cause any problems with apple when they review my app? And is there anything that I am doing wrong to make this happen?

note: the UITableView is being populated from a plist which is being moved to the documents directory. My original thought was that the UITableView is trying to populate the list before the plist has successfully been moved to the documents directory. So I tried to call [self.tableView reloadData]; at the end of viewDidLoad method but I got the same result.

@implementation AppDelegate

- (void)createEditableCopyOfDatabaseIfNeeded
{
    //TESTING FOR EXISTENCE
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [searchPaths lastObject];
    NSString *writeableDBPath = [documentsDirectory stringByAppendingPathComponent:@"ScotchList.plist"];

    BOOL dbexists = [fileManager fileExistsAtPath:writeableDBPath];
    if (!dbexists) {
        // The writeable database does not exist, so copy the default to the appropriate location.
        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"ScotchList.plist"];

        NSError *error;
        BOOL success = [fileManager copyItemAtPath:defaultDBPath toPath:writeableDBPath error:&error];
        if (!success) {
            NSAssert1(0, @"Failed to create writeable database file with message '%@'.", [error localizedDescription]);
        }
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPhone" bundle:nil];
        self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

        self.window.rootViewController = self.navigationController;
    } else {
        MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
        UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

        masterViewController.detailViewController = detailViewController;

        self.splitViewController = [[UISplitViewController alloc] init];
        self.splitViewController.delegate = detailViewController;
        self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];

        self.window.rootViewController = self.splitViewController;
    }
    [self.window makeKeyAndVisible];
    [self createEditableCopyOfDatabaseIfNeeded];
    [application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
    return YES;
}

MasterViewController.m

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.sections = [[NSMutableDictionary alloc] init];
    BOOL found;

    // Loop through the whiskys and create our keys
    for (NSMutableDictionary *whisky in self.drinks)
    {
        NSString *c = [[whisky objectForKey:NAME_KEY] substringToIndex:1];

        found = NO;

        for (NSString *str in [self.sections allKeys])
        {
            if ([str isEqualToString:c])
            {
                found = YES;
            }
        }

        if (!found)
        {
            [self.sections setValue:[[NSMutableArray alloc] init] forKey:c];
        }
    }
    // Loop again and sort the whiskys into their respective keys
    for (NSMutableDictionary *whisky in self.drinks)
    {
        [[self.sections objectForKey:[[whisky objectForKey:NAME_KEY] substringToIndex:1]] addObject:whisky];
    }
    // Sort each section array
    for (NSString *key in [self.sections allKeys])
    {
        [[self.sections objectForKey:key] sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:NAME_KEY ascending:YES]]];
    }
        [self.tableView reloadData];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.582d0e
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0x015/255.0 green:0x04/255.0 blue:0x04/255.0 alpha:1];
    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBackground.png"]];
    self.navigationItem.leftBarButtonItem = self.editButtonItem;
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];
    self.navigationItem.backBarButtonItem.tintColor = [UIColor colorWithRed:0x3e/255.0 green:0x3e/255.0 blue:0x3e/255.0 alpha:1];
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
    self.navigationItem.rightBarButtonItem = addButton;
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:0x015/255.0 green:0x04/255.0 blue:0x04/255.0 alpha:1];

    UIImage *titleImage = [UIImage imageNamed:@"whiskeyTitle.png"];
    self.navigationItem.titleView = [[UIImageView alloc]initWithImage:titleImage];

    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [searchPaths lastObject];
    NSString *writeableDBPath = [documentsDirectory stringByAppendingPathComponent:@"ScotchList.plist"];

    NSMutableArray *tmpArray = [[NSMutableArray alloc]initWithContentsOfFile:writeableDBPath];

    self.drinks = tmpArray;
    deletedDrink = [[NSMutableArray alloc]init];
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(applicationDidEnterBackground:) 
                                                 name:UIApplicationDidEnterBackgroundNotification
                                               object:nil];

    //Register for application exiting information so we can save data
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];

    bookCover = [[UIImageView alloc]init];
    bookCover.image = [UIImage imageNamed:@"Default.png"];
    openBookButton = [[UIButton alloc]init];
    [openBookButton addTarget:self action:@selector(goToPage:flipUp:) forControlEvents:UIControlEventTouchUpInside];
    bookCover.frame = CGRectMake(0, 0, 320, 480);
    openBookButton.frame = bookCover.frame;

    [self.navigationController.view addSubview:bookCover];
    [self.navigationController.view addSubview:openBookButton];
    [self.tableView reloadData];
}

OK UPDATE

I have NSLog()‘d my array that pulls from the plist in the viewDidLoad when the app is initially built and ran (installed) on the phone it logs null. If I stop and re-build and run it returns the information from the plist (not null).

  • 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-06-07T14:39:47+00:00Added an answer on June 7, 2026 at 2:39 pm

    GOT IT. Basically I have a method in my appDelegate.m (createEditableCopyOfDatabaseIfNeeded) that checks for a database (in my case a plist) inside my documents directory. If there is already an existing plist it will not overwrite it. If there isn’t a plist then it moves the plist that I have shipped with the app to the documents directory. then inside of applicationDidFinishLaunchingWithOptions: method I called [self createEditableCopyOfDatabaseIfNeeded]; which seems like it should be all good. However inside of the applicationDidFinishLaunchingWithOptions method there is the if statement to check the currentDevice userInterfaceIdiom I was calling [self createEditableCopyOfDatabaseIfNeeded]; after the if and the else that checks the interfaceIdiom. I simply just moved up into the if statement where the userInterfaceIdiom is the iPhone.

    Below I have commented where the issue was and where I moved it to solve it.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPhone" bundle:nil];
            self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    
            self.window.rootViewController = self.navigationController;
    
            //THIS WAS THE SOLUTION RIGHT BELOW.
            [self createEditableCopyOfDatabaseIfNeeded];
        } else {
            MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
            UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    
            DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
            UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
    
            masterViewController.detailViewController = detailViewController;
    
            self.splitViewController = [[UISplitViewController alloc] init];
            self.splitViewController.delegate = detailViewController;
            self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
    
            self.window.rootViewController = self.splitViewController;
        }
        [self.window makeKeyAndVisible];
        //THIS IS WHERE [self createEditableCopyOfDatabaseIfNeeded]; WAS ORIGINALLY WHICH WAS CAUSING THE PROBLEM
        [application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
i want to parse a xhtml file and display in UITableView. what is the

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.