0

我有一个具有初始表的代码,当您单击索引时,它会加载另一个视图。我有正确填充数组的代码,但是我刚刚使用的代码不会使用数组填充表。我有几乎完全相同的代码来填充我的主表,但它不会填充。继承人的代码:

- (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;
}

由于某种原因,它不会打印出数组。我将数组作为属性并在 viewDidLoad 方法中初始化:

    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];
}
4

1 回答 1

1

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 ?
于 2013-05-14T03:27:43.317 回答