初期テーブルを持つコードがあり、インデックスをクリックすると別のビューが読み込まれます。配列を正しく設定しているコードがありますが、配列を使用してテーブルにデータを設定しません。メイン テーブルの作成に使用したものとほぼ同じコードを使用していますが、作成されません。コードは次のとおりです。
- (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];
}