Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i pass data from SQLite into a UITextVIew?
    primarykey
    data
    text
    <p>I'm trying to retrieve data form the database and display it out in the UITextView but when i run the project, the TextView would be empty.</p> <p>AppDelegate.m:</p> <pre><code>-(void) readPlotsFromDatabase { // Setup the database object sqlite3 *database; // Init the Array ps = [[NSMutableArray alloc] init]; // Open the database from the users filessytem if(sqlite3_open([databasePath UTF8String], &amp;database) == SQLITE_OK) { // Setup the SQL Statement and compile it for faster access const char *sqlStatement = "select * from Plot"; sqlite3_stmt *compiledStatement; if(sqlite3_prepare_v2(database, sqlStatement, -1, &amp;compiledStatement, NULL) == SQLITE_OK) { // Loop through the results and add them to the feeds array while(sqlite3_step(compiledStatement) == SQLITE_ROW) { // Read the data from the result row NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)]; // Create a new object with the data from the database Plot *plots = [[Plot alloc] description:aDescription]; // Add the object to the Array [ps addObject:plots]; // [themes release]; } } // Release the compiled statement from memory sqlite3_finalize(compiledStatement); } sqlite3_close(database); } </code></pre> <p>Plot.h:</p> <pre><code>@interface Plot : NSObject { NSString *description; } @property (nonatomic,retain) NSString *description; -(id)description:(NSString *)d; @end </code></pre> <p>Plot.m:</p> <pre><code>@implementation Plot @synthesize description; -(id)description:(NSString *)d { self.description = d; return self; } @end </code></pre> <p>PlotViewController.h:</p> <pre><code>@interface PlotViewController : UIViewController { IBOutlet UITextView *plotDescription; Plot *plots; AppDelegate *appDelegate; NSString *plotDes; } @property (nonatomic, retain) IBOutlet UITextView *plotDescription; @property (nonatomic, retain) Plot *plots; @property (nonatomic, retain) NSString *plotDes; @end </code></pre> <p>PlotViewController.m:</p> <pre><code>- (void)viewDidLoad { appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; plotDescription.text = plots.description; [super viewDidLoad]; } </code></pre> <p>EDIT:</p> <p>I change my PlotViewController.m to this now and it is able to work.</p> <pre><code>- (void)viewDidLoad { appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; Plot *p = (Plot *)[appDelegate.ps objectAtIndex:0]; plotDescription.text = p.description; [super viewDidLoad]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload