Step 1: add the fmdb class library to the project in the new project,
Step 2: Put the. DB database in the following directory:
/Users/Apple/library/Application Support/iPhone simulator/6.1/applications/06a47f8b-23ea-48d5-80a5-54cf37d0d8b8/documents/tcfexam. DB
Database
Step 3: Enter the followingCode:
/// Textoneviewcontroller. M // tcfexamtextone /// created by Apple on 13-7-13. // copyright (c) 2013 apple. all rights reserved. // # import "textoneviewcontroller. H "# import" fmdatabase. H "# import" fmresultset. H "@ interface textoneviewcontroller () @ end @ implementation textoneviewcontroller-(ID) initwithnibname :( nsstring *) nibnameornil bundle :( nsbundle *) {self = [Super initwithnibname: nibna Meornil Bundle: nibbundleornil]; If (Self) {// custom initialization} return self;}-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view from Its nib .} -(void) didreceivememorywarning {[Super didreceivemorywarning]; // dispose of any resources that can be recreated .} -(ibaction) didsearch :( ID) sender {nsarray * paths = nssearchpathfordirectoriesindomains (nsdoc Umentdirectory, nsuserdomainmask, yes); nsstring * documentpath = [paths objectatindex: 0]; nsstring * dbpath = [documentpath stringbyappendingpathcomponent: @ "tcfexam. DB "]; fmdatabase * database = [fmdatabase databasewithpath: dbpath]; If (! [Database open]) {return;} // query the allthequstions fmresultset * resultset = [database executequery: @ "select * From allthequstions"]; // read data row by row while ([resultset next]) {// obtain the data nsstring * History = [resultset stringforcolumn: @ "History"]; nsstring * question = [resultset stringforcolumn: @ "Question"]; nslog (@ "History: % @, question: % @", history, question );} [database close];} @ end
Step 4: The output result is as follows: