Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Draw This
($0.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-28-2009, 08:37 AM   #13 (permalink)
Chetmun
Registered Member
 
Join Date: Jul 2009
Location: Cleveland
Posts: 21
Chetmun is on a distinguished road
Send a message via AIM to Chetmun
Default

Quote:
Originally Posted by eddietr View Post
PM is private message.

NVM, seems you dont' have private messages enabled?

In any case, maybe you'll figure it out tomorrow or you can post more of the project. I don't see anything (yet) from what you've posted.
Obviously new to the forum. Can't seem to do anything on my CP. So I'll just paste into here. I've stripped out the irrelevant code so it's clearer and smaller. What's left should work on its own. The POI class is just a data structure, could be anything - a couple of strings in this example. I'm a Java programmer if you can't tell and this .m, .h stuff and the property and synthesizing is driving me nuts. OK, here's the code. Hope it makes sense.


OtherClass.h

// nothing in here related to this problem


OtherClass.m

#import "OtherClass.h"
#import "MyAppDelegateAppDelegate.h"
#import "POI.h"

@class MyAppDelegateAppDelegate;

@implementation OtherClass

- (void) viewDidLoad
{
[super viewDidLoad];

MyAppDelegateAppDelegate *appDelegate = (MyAppDelegateAppDelegate *)[[UIApplication sharedApplication] delegate];
// breakpoint here, appDelegate appears to be uninitialized (the pois array has 0 elements)
POI *poi = [appDelegate.pois objectAtIndex:0];
}


MyAppDelegate.h

#import <UIKit/UIKit.h>

@class OtherClass;

@interface MyAppDelegateAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
{
UIWindow *window;
UITabBarController *tabBarController;
NSFileManager *FileManager;
NSString *databaseName;
NSString *databasePath;
NSMutableArray *pois;
}

-(void) readPOIsFromDatabase;
-(void) checkAndCreateDatabase;

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) NSMutableArray *pois;

@end


MyAppDelegate.m

#import "MyAppDelegateAppDelegate.h"
#import "sqlite3.h"
#import "POI.h"

@implementation MyAppDelegateAppDelegate

@synthesize window;
@synthesize tabBarController;
@synthesize pois;

- (void) applicationDidFinishLaunchingUIApplication *)application
{
databaseName = @"MyAppDelegate.sql";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
[self readPOIsFromDatabase];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}

-(void) readPOIsFromDatabase
{
sqlite3 *database;
pois = [[NSMutableArray alloc] init];
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
const char *sqlStatement = "select name, type from pois";
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
while (sqlite3_step(compiledStatement) == SQLITE_ROW)
{
NSString *aName = [NSString stringWithUTF8Stringchar *)sqlite3_column_text(compiledStatement, 0)];
NSString *aType = [NSString stringWithUTF8Stringchar *)sqlite3_column_text(compiledStatement, 1)];
POI *poi = [[POI alloc] initWithName:aName tp:aType];
[pois addObjectoi];
[poi release];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}

-(void) checkAndCreateDatabase
{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:databasePath];
if (success) return;
NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];
[fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil];
[fileManager release];
}

- (void) dealloc
{
[tabBarController release];
[window release];
[super dealloc];
}

@end
Chetmun is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,014
Threads: 93,862
Posts: 401,918
Top Poster: BrianSlick (7,962)
Welcome to our newest member, Shimi574
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.