title: Retrieve all rows inserted in sqlite database and display in table view cells containing labels as subviews with different sections
body: <p>I am newbie to objective-c and sqlite.I have inserted data in to table using sqlite successfully.My project contains 2 pages</p>
  
  <p>Add Reminder page:Where user enters data and clicks save which is the right navigation bar</p>
  
  <p>View Reminder page:This is where the user views the saved reminder in cells of table view,</p>
  
  <p>i.e. 1st reminder on 1st cell,2nd reminder on 2nd cell and so on...</p>
  
  <p>I have made my task much easier to specify the number of sections using the following code,means the number of saved reminders is equal to number of sections in view reminder table</p>
  
  <pre><code>-(NSInteger)numberOfSectionsInTableView:(UITableView *)view
  {    
      numTableRecords = -1;
      sqlite3_stmt *statement;
      if (sqlite3_open([self.databasePath UTF8String], &amp;remindersDB) == SQLITE_OK) 
      {
          NSString *sqlStatement = [NSString stringWithFormat: @"select count(*) from reminders"];
          const char *sql = [sqlStatement cStringUsingEncoding:NSUTF8StringEncoding];
          if(sqlite3_prepare_v2(remindersDB, sql, -1, &amp;statement, NULL) == SQLITE_OK) 
          {          
              while(sqlite3_step(statement) == SQLITE_ROW) 
              {
                  numTableRecords = sqlite3_column_int(statement, 0);
              }
          }
          else 
          {
              printf("could not prepare statement: %s\n", sqlite3_errmsg(remindersDB));
          }
      }
  
      else 
      {
          NSLog(@"Error in Opening Database File");
      }
      sqlite3_close(remindersDB);
      NSLog(@"Number of records = %d",numTableRecords);
      return numTableRecords; 
  
  }
  </code></pre>
  
  <p>Based on suggestion given in the following link,pretty much similar to my requirement:</p>
  
  <p><a href="https://stackoverflow.com/questions/8475446/populate-the-table-view-sections-with-rows-of-table-in-sqlite-database-in-an-ord">Populate the table view sections with rows of table in sqlite database in an order</a></p>
  
  <p>I took an array and inserted the retrieved data as objects to the array as shown in the following:</p>
  
  <pre><code>-(void)viewWillAppear:(BOOL)animated
  {
  
      //Retrieve the values of database
      const char *dbpath = [self.databasePath UTF8String];
      sqlite3_stmt *statement;
      if (sqlite3_open(dbpath, &amp;remindersDB) == SQLITE_OK)
      {
          NSString *querySQL = [NSString stringWithFormat:@"SELECT * FROM reminders"];
          NSLog(@"Data = %@",querySQL);
  
          const char *query_stmt = [querySQL UTF8String];
  
          if (sqlite3_prepare_v2(self.remindersDB ,query_stmt , -1, &amp;statement, NULL) == SQLITE_OK)
          {
              if (sqlite3_step(statement) == SQLITE_ROW)
              {
                  ID = [[[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)]autorelease];
  
                  nameField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)]autorelease];                    
  
                  eventField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)]autorelease];
  
                  dateField = [[[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 3)]autorelease];
              } 
  
              sqlite3_finalize(statement);
          }
          sqlite3_close(self.remindersDB);
      }
      [array addObject:ID];
      [array addObject:nameField];
      [array addObject:eventField];
      [array addObject:dateField];
      [self.theTable reloadData];
      [super viewWillAppear:YES];
  }
  </code></pre>
  
  <p>Now in (UITableViewCell)-cell for row at index path I took 4 labels and added them as subviews and assigned the [array objectAtIndex:indexPath.row] to label.text,i.e.:</p>
  
  <pre><code> - (UITableViewCell *)tableView:(UITableView *)view cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
      //NSString *CellId = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
  
      UITableViewCell *cell = (UITableViewCell *)[view dequeueReusableCellWithIdentifier:nil];
  
      if (cell == nil)
      {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil] autorelease];
          view.backgroundColor = [UIColor clearColor];
          cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"reminderbutton.png"]];
  
          label1 = [[[UILabel alloc]initWithFrame:CGRectMake(26, 3, 30, 40)]autorelease];
          label1.backgroundColor = [UIColor clearColor];
          label1.textColor = [UIColor whiteColor];
  
          label2 = [[[UILabel alloc]initWithFrame:CGRectMake(45, 3, 100, 40)]autorelease];
          label2.backgroundColor = [UIColor clearColor];
          label2.textColor = [UIColor whiteColor];
  
          label3 = [[[UILabel alloc]initWithFrame:CGRectMake(119, 3, 100, 40)]autorelease];
          label3.backgroundColor = [UIColor clearColor];
          label3.textColor = [UIColor whiteColor];
  
          label4 = [[[UILabel alloc]initWithFrame:CGRectMake(198, 3, 120, 40)]autorelease];
          label4.backgroundColor = [UIColor clearColor];
          label4.textColor = [UIColor whiteColor];
  
      }
   label1.text = [array objectAtIndex:indexPath.row];
      label2.text = [array objectAtIndex:indexPath.row];
      label3.text = [array objectAtIndex:indexPath.row];
      label4.text = [array objectAtIndex:indexPath.row];
  
      [cell addSubview:label1];
      [cell addSubview:label2];
      [cell addSubview:label3];
      [cell addSubview:label4];
  
      return cell;
  }
  </code></pre>
  
  <p>Nothing is getting displayed on cells,please help me to fix this issue.Struggling very bad for this,as I am new to objective-c,I would be very happy if any one comes up with detailed explanation and solution.Sorry for the question if it sounds stupid</p>
  
  <p>Thanks all in advance :)</p>