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