Sql Random statement help on xcode and uilabel -
i making first app quiz game. managed until create database sqlite , load categories table uitableview. need on how create next single screen load questions , it's answers labels specific category choise , how represent on fields. hope can understand problem. thank in advance!
ok managed import question table labels. here code:
-(nsmutablearray *) categorieslist{ categories = [[nsmutablearray alloc] initwithcapacity:10]; @try { nsfilemanager *filemgr = [nsfilemanager defaultmanager]; nsstring *dbpath = [[[nsbundle mainbundle] resourcepath ]stringbyappendingpathcomponent:@"categories.sqlite"]; bool success = [filemgr fileexistsatpath:dbpath]; if(!success) { nslog(@"cannot locate database file '%@'.", dbpath); } if(!(sqlite3_open([dbpath utf8string], &db) == sqlite_ok)) { nslog(@"an error has occured: %s", sqlite3_errmsg(db)); } const char *sql = "select * questions category 1"; sqlite3_stmt *sqlstatement; if(sqlite3_prepare(db, sql, -1, &sqlstatement, null) != sqlite_ok) { nslog(@"problem prepare statement: %s", sqlite3_errmsg(db)); }else{ while (sqlite3_step(sqlstatement)==sqlite_row) { categories * choise = [[categories alloc] init]; question.text = [nsstring stringwithutf8string:(char *) sqlite3_column_text(sqlstatement, 1)]; answer1.text = [nsstring stringwithutf8string:(char *) sqlite3_column_text(sqlstatement, 2)]; answer2.text = [nsstring stringwithutf8string:(char *) sqlite3_column_text(sqlstatement, 3)]; answer3.text = [nsstring stringwithutf8string:(char *) sqlite3_column_text(sqlstatement, 4)]; answer4.text = [nsstring stringwithutf8string:(char *) sqlite3_column_text(sqlstatement, 5)]; [categories addobject:choise]; } } sqlite3_finalize(sqlstatement); } @catch (nsexception *exception) { nslog(@"problem prepare statement: %s", sqlite3_errmsg(db)); } @finally { sqlite3_close(db); return categories; } } @end
can explain me how make random choose of questions labels , go next question of same category?thank in advance
Comments
Post a Comment