最初にアプリを作成していUITableView
ますが、初めてスマートフォンでアプリを作成して実行すると、何もUITableView
表示されません。実行を停止してから再構築して再度実行すると、すべてのデータが表示されます。また、アプリがすでに私の電話にある場合、それは正常に構築され、実行されます。これは最初の最初のビルドであり、電話にアプリを「インストール」してUITableView
空のままにしたときに実行されます。彼らが私のアプリをレビューするときに、これがアップルに問題を引き起こすかどうか知りたいですか?そして、これを実現するために私が間違っていることはありますか?
注:はUITableView
、ドキュメントディレクトリに移動されているplistから入力されています。私の当初の考えはUITableView
、plistがドキュメントディレクトリに正常に移動される前に、がリストにデータを入力しようとしているというものでした。[self.tableView reloadData];
そのため、メソッドの最後で呼び出しようとしましたviewDidLoad
が、同じ結果が得られました。
@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アップデート
私は、アプリが最初に構築され、電話で実行(インストール)さNSLog()
れたときに、plistからプルする配列をviewDidLoad
ログに記録しました。停止して再構築して実行すると、plistからの情報が返されます(nullではありません)。