heinst
heinst

Reputation: 8786

Populating UITableView on a secondary view

I have code that has an initial table and when you click an index, it loads another view. I have code that is populating an array correctly, but the code I have just wont populate the table using the array. I have almost the exact same code that I used to populate my main table, but it won't populate. Heres the code:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
}
cell.selectionStyle = UITableViewCellSelectionStyleBlue;

NSLog(@"Questions array = %@", self.answersArray);

cell.textLabel.text = [_answersArray objectAtIndex:indexPath.row];

return cell;
}

For some reason it wont print out the array. I have the array as a property and being initialized in the viewDidLoad method:

    NSInteger row = _indexOfQuestion.row;
_tempStr = [NSString stringWithFormat:@"http://**.***.**.**/getAnswer.php?num=%d", row];
self.answersArray = [[NSMutableArray alloc] init];
self.answersArray = [NSMutableArray arrayWithObject: _selectedQuestion];
for(int i = 1; i <= 4; i++)
{
    _hostStr = [_tempStr stringByAppendingFormat:@"&ans=answer%d", i];
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString: _hostStr]];
    NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding:NSASCIIStringEncoding];
    [self.answersArray addObject: serverOutput];
}

Upvotes: 0

Views: 130

Answers (1)

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73638

Some of the things that might have gone wrong -

  1. Is the NSArray populated with the data? (you said the data is present).
  2. If data is present, then see if you have linked UITabelView in Interface Builder with the variable in your code.
  3. Did you link your UITableView delegate and dataSource to the correct file?
  4. Did you inherit the UITableViewDelegate and UITableViewDataSource in the .h file ?

Upvotes: 1

Related Questions