title: iOS 7 - TableView not displaying values properly
body: <p>Sorry but I've been stuck in this problem for quite some time and I can't figure out why. I have a ViewController that has 2 TableViews, it took me some time to manage the functions but it's running well now. Initially, I had some static strings as display for the table cells just to check if I can make it run. After managing to do so, I then used my Arrays as sources for the table contents. The first table populates just fine, however, the second one displays blanks. </p>
  
  <p>The cellForRowAtIndexPath function:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
      UITableViewCell *priceCell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:PriceCellIdentifier];
      UITableViewCell *discountCell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:DiscountCellIdentifier];
  
      if(tableView == self.priceTable){
          [priceCell.textLabel setText:[NSString stringWithString:[priceArray objectAtIndex:indexPath.row]]];
          return priceCell;
      }
      else /*if(tableView == self.discountTable)*/ {
          [discountCell.textLabel setText:[NSString stringWithString:[discountArray objectAtIndex:indexPath.row]]];
  
          return discountCell;
      }
  
  }
  </code></pre>
  
  <p>This is rather confusing since I didn't do anything but change where I am getting the value that the table cell would display. I also checked my <code>discountArray</code> and it is not empty, I logged out the values from inside this function and I can see the said values. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is my viewDidLoad function:</p>
  
  <pre><code>- (void)viewDidLoad{
      [super viewDidLoad];
  
      priceArray = [[NSMutableArray alloc] init];
      discountArray = [[NSMutableArray alloc] init];
      NSLog(@"received info %@", [self.selectedItem description]);
      [self executeSQL];
  
  }
  </code></pre>
  
  <p>executeSQL is the function that would initialise the <code>priceArray</code> and <code>discountArray</code></p>
  
  <pre><code>- (void) executeSQL{
    // Getting the database path.
    NSArray  *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docsPath = [paths objectAtIndex:0];
    NSString *dbPath = [docsPath stringByAppendingPathComponent:@"itemList.db"];
  
    FMDatabase *database = [FMDatabase databaseWithPath:dbPath];
    [database open];
  
    NSMutableString *sqlQuery = [NSMutableString stringWithString:@"SELECT ITEMNAME, BRAND, GROUPID, CLASS, UOM, AMT, AMT2, AMT3, DISC, DISC2, DISC3 FROM ItemList WHERE ITEMNAME = '"];
  
    [sqlQuery appendString:selectedItem];
    [sqlQuery appendString:@"'"];
  
  
    // Query result
    FMResultSet *resultsWithNameLocation = [database executeQuery:sqlQuery];
  
    [priceArray removeAllObjects];
    [discountArray removeAllObjects];
  
    //we get the results here.
    while([resultsWithNameLocation next]) {
  
        //for the AMT, AMT2, and AMT3
        if([[NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"AMT"]] isEqualToString:@"(null)"]){
            [priceArray addObject:@""];
        }
        else{
            [priceArray addObject:[resultsWithNameLocation stringForColumn:@"AMT"]];
        }
  
        if([[NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"AMT2"]] isEqualToString:@"(null)"]){
            [priceArray addObject:@""];
        }
        else{
            [priceArray addObject:[resultsWithNameLocation stringForColumn:@"AMT2"]];
        }
  
        if([[NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"AMT3"]] isEqualToString:@"(null)"]){
            [priceArray addObject:@""];
        }
        else{
            [priceArray addObject:[resultsWithNameLocation stringForColumn:@"AMT3"]];
        }
        //end of priceArray
  
        //for DISC, DISC2, and DISC3
  
        if([[NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"DISC"]] isEqualToString:@"(null)"]){
            [discountArray addObject:@""];
        }
        else{
            [discountArray addObject:[resultsWithNameLocation stringForColumn:@"DISC"]];
        }
  
        if([[NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"DISC2"]] isEqualToString:@"(null)"]){
            [discountArray addObject:@""];
        }
        else{
            [discountArray addObject:[resultsWithNameLocation stringForColumn:@"DISC2"]];
        }
  
        if([[NSString stringWithFormat:@"%@",[resultsWithNameLocation stringForColumn:@"DISC3"]] isEqualToString:@"(null)"]){
            [discountArray addObject:@""];
        }
        else{
            [discountArray addObject:[resultsWithNameLocation stringForColumn:@"DISC3"]];
        }
  
        NSLog(@"DISC = %@", discountArray[0]);
        NSLog(@"DISC2 = %@", discountArray[1]);
        NSLog(@"DISC3 = %@", discountArray[2]);
  
    }
    [database close];
  
  }
  </code></pre>
  
  <p>The log statements of the <code>executeSQL</code> function execute first before the <code>cellForRowAtIndexPath</code> function which tell me that my arrays have contents. They are not just being displayed properly.</p>
  
  <p>I am confused because if I replace <code>[discountCell.textLabel setText:[NSString stringWithString:[discountArray objectAtIndex:indexPath.row]]];</code> with <code>[discountCell.textLabel setText:[NSString stringWithFormat:@"Sample Text"]];</code> then it works.</p>
  
  <p>Can someone help me with this? Thank you.</p>