User |
Post |
8:14 pm
October 13, 2008
|
cmcintosh2
iCoder
|
|
|
|
|
posts 9
|
|
|
Okay, so i am looking at making a sqlite similar program.
My program will have Categories of Games, and Rules for those games. The table structure looks somewhat like:
category:
pk int primary key, title varchar(), active(BOOL)
game:
pk int primary key, catId int, title varchar(), active(BOOL)
rule:
pk int primary key, gameId int, ruleText text
Okay so far, I have my first table populating from the category list(user clicks cell and goes to next view). I have it pushing the view for a new tableViewController which should be populating with the games that are of the selected category.
On first run I am just trying to get it to populate with any games, but I am getting an error:: -[GameViewController myGames]: unrecognized selector sent to instance, from my understanding from what i have read online i have to do something called a -performSelectorOnMainThread, doing so apparently will run the required function(which right now the object for game, appDelegate, and viewController(s) are all the same in functionality as the ones for category table).
So not sure where to go from here as far as creating a function that is called to then populate the table. I am going to fiddle around a bit more, but any pointers would be great help.
|
|
9:00 pm
October 13, 2008
|
cmcintosh2
iCoder
|
|
|
|
|
posts 9
|
|
|
Okay not sure if this is along the correct path, but Ill try. Should i maybe run the query and build the array in the rootViewController, then send it to the gameViewController (second tableView) when the user clicks on the cell?
Not sure if this is along the right road, but maybe someone will shoot me an idea. Thanks in advance.
|
|
6:05 am
October 16, 2008
|
cmcintosh2
iCoder
|
|
|
|
|
posts 9
|
|
|
Still having problems nailing it down, but i think i may try the tack of placing all the code to call the new table in the first tableView controller. Any suggestions would be great.
|
|
10:21 am
October 16, 2008
|
Admin
|
|
brandontreb
|
|
|
posts 88
|
|
|
I'm not quite sure I understand the problem. Could you please maybe post some screenshots to highlight it?
|
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-Edsger Dijkstra
|
|
11:00 am
October 16, 2008
|
cmcintosh2
iCoder
|
|
|
|
|
posts 9
|
|
|
Cant get screen shots at the moment, i will post the error and describe what i am doing.
So i have the first table view, this view is pulling a list of categories from an sqlite db. When you click on a category, it should then load up another table view with a list of the games that match to that category, also in the database. However, what is happening is the following run-time error:
2008-10-16 12:58:10.848 iDrinkMe[34111:20b] *** -[iDrinkMeAppDelegate gamesArray]: unrecognized selector sent to instance 0×44fff0
2008-10-16 12:58:10.849 iDrinkMe[34111:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[iDrinkMeAppDelegate gamesArray]: unrecognized selector sent to instance 0×44fff0'
2008-10-16 12:58:10.851 iDrinkMe[34111:20b] Stack: (
2440716619,
2535096571,
2440745802,
2440739148,
2440739346,
13762,
816441448,
816442476,
816513517,
816465484,
837317240,
837317032,
837315376,
837314643,
2440210882,
2440217636,
2440219896,
829005112,
829005309,
816175835,
816221412,
8972,
8826
)
I have checked the names and they are correct, and if i switch the first tableView to test the code i setup for the games list(created new nsObject: games, and a new array gamesArray) it works. So not really sure what im doing wrong.
|
|
9:23 pm
October 18, 2008
|
cmcintosh2
iCoder
|
|
|
|
|
posts 9
|
|
|
Okay, this is an update of what i am doing. I had to go back and move the code that was pulling the list of games into the same appDelegate class that was pulling the list of cateogries, once i did that things all clicked. So I am now working on limiting the results that are pulled to just the ones that match the selected category.
To do this I added an id field in the games table called cid this is matching with the primary key of the category. So now I need to find some way of passing the primary key value to the sql value in the game object so that it only displays the games that match. I also need to find a way to limit the number to table cells generated to just the number of games that match that result as well.
I will keep you guys up to date as it moves along.
|
|
10:36 pm
October 18, 2008
|
cmcintosh2
iCoder
|
|
|
|
|
posts 9
|
|
|
Okay so here is my idea for the program.
I have the array that is built from the sql row; im going to call it games.
What i want to do(dont know if it is most effecient or not, but here is my logic):
1. loop thorugh category,
2. run an sql statement pulling only the games that match the category, store the rows in an array.
3. store the complete array from this run into a holder array, lets call it gameHolder
Once that is done, when the user clicks on a category it will find the appropiate gameHolder array to match with the indexPath.row. It will get the count(tells us the number of table cells to build in next screen) and then continues to second screen.
Currently I am not sure if i am building it write or calling it correct so ill toss the code i have in here below and maybe someone can give me some pointers or looking at it in a browser will give me some insight.
-(void)initializeDatabase{
NSMutableArray *categoryArray = [[NSMutableArray alloc] init];
NSMutableArray *gamesArrayb = [[NSMutableArray alloc] init];
self.categories = categoryArray;
self.games = gamesArrayb;
[categoryArray release];
[gamesArrayb release];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myData.sqlite"];
if(sqlite3_open([path UTF8String], &database) == SQLITE_OK){
const char *categorySQL = “SELECT pk FROM category WHERE active = 1″;
sqlite3_stmt *statement;
const char *gameSQL = “SELECT pk FROM game WHERE cid = ? AND active = 1″;
sqlite3_stmt *gameStatement;
if(sqlite3_prepare_v2(database, gameSQL, -1, &gameStatement, NULL) != SQLITE_OK){
NSAssert1(0, @”Error: Failed to prepare statement with message '%s'.”, sqlite3_errmsg(database));
}
if(sqlite3_prepare_v2(database, categorySQL, -1, &statement, NULL) == SQLITE_OK){//okay database has init okay and we have found some results
while(sqlite3_step(statement) == SQLITE_ROW){we get results for each row
int primaryKey = sqlite3_column_int(statement, 0);
category *cat=[[category alloc] initWithPrimaryKey:primaryKey database:database];
[categories addObject:cat];
[cat release];
//START PULLING THE GAMES FOR EACH CATEGORY
sqlite3_bind_int(gameStatement, 1, primaryKey);
NSMutableArray *gamesArray = [[NSMutableArray alloc] init];
while(sqlite3_step(gameStatement) == SQLITE_ROW){
int primeKey = sqlite3_column_int(gameStatement, 0);
game *gam = [[game alloc] initWithPrimaryKey:primeKey database:database];
[gamesArray addObject:gam];//is this right??
[gam release];
}
if(gamesArray.count > 0){
[superGamesArrays addObject:gamesArray];//is this right??
[gamesArray release];
}
}
}
sqlite3_finalize(statement);
} else {
sqlite3_close(database);
NSAssert1(0, @”Failed to open database with message '%s'.”, sqlite3_errmsg(database));
}
}
thanks in advance for any suggestions.
|
|