ユーザーがいくつかの情報(質問と選択肢)を入力するはずのテーブルビューフォームがあります。基本的に、ユーザーが最後のセクションをクリックするとテキストフィールドやその他の要素が収集されます。 didSelectRowAtIndexPath
機能でUITableViewControllerからUITableViewの0番目のセクションに到達できません
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==0) {
AskCellQuestion *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"askQuestionCell"];
if (cell == nil) {
cell = [[AskCellQuestion alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"askQuestionCell"];
}
...
cell.questionText.delegate = cell;
return cell;
} else if (indexPath.section==1) {
if (indexPath.row < numberOfChoices) {
AskCellChoice *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"askChoiceCell"];
if (cell == nil) {
cell = [[AskCellChoice alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"askChoiceCell"];
}
...
cell.choiceText.delegate = cell;
...
return cell;
} else {
AskCellChoiceAdd *cell;
cell = [tableView dequeueReusableCellWithIdentifier:@"askChoiceAddCell"];
if (cell == nil) {
cell = [[AskCellChoiceAdd alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"askChoiceAddCell"];
}
return cell;
}
} else if (indexPath.section==2) {
...
}
// Configure the cell...
return 0;
}
、私はこれらのテキストフィールドにアクセスし、それらの値を取るしようとしている:
UITableView * questionFormView = [self tableView];
AskCellQuestion * questionCell = (AskCellQuestion *)[questionFormView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSString * questionText = questionCell.questionText.text;
NSLog(@"TXt: %@",questionText);
UIImage * questionImage = questionCell.questionImage;
NSLog(@"IMG: %@",questionImage);
NSString * questionVideo = questionCell.youtubeVideoID;
NSLog(@"VID: %@",questionVideo);
for (int i = 0; i < numberOfChoices; i++) {
AskCellChoice * choiceCell = (AskCellChoice *)[questionFormView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:1]];
NSLog(@"C TXt: %@",choiceCell.choiceText.text);
NSLog(@"C IMG: %@",choiceCell.choiceImage);
NSLog(@"C VID: %@",choiceCell.youtubeVideoID);
}
これは、コンソールでこの出力を与えている。要するに
2012-03-17 01:04:46.700 x[2346:207] TXt: (null)
2012-03-17 01:04:46.701 x[2346:207] IMG: (null)
2012-03-17 01:04:46.701 x[2346:207] VID: (null)
2012-03-17 01:04:46.701 x[2346:207] C TXt: TEST CHOICE 1
2012-03-17 01:04:46.701 x[2346:207] C IMG: <UIImage: 0x6ec75f0>
2012-03-17 01:04:46.702 x[2346:207] C VID: FMij4sZioBM
2012-03-17 01:04:46.702 x[2346:207] C TXt: TEST CHOICE 2
2012-03-17 01:04:46.702 x[2346:207] C IMG: <UIImage: 0x6e7ce30>
2012-03-17 01:04:46.702 x[2346:207] C VID: GfIcEzFzqKE
を、私はセクション0のテキストフィールドにアクセスすることはできません。私は2番目の行を追加しようとし、それもnullを返しました。私は質問と選択のセルのセクションを交換しようとしました。その時間は選択肢に対応するセクション0に対してnullを返しました。質問セルはうまくいきました。セクション番号を増やしてみましたので、質問セルはセクション1にあり、選択肢はセクション2などでした。セクション1ではnullが返されました。何が起こっているのか分からず、本当に奇妙な問題です。
indexPath
は、セクション0の行のインデックスパスに等しい。しかし、それはないとき、私は[NSIndexPath indexPathForRow:0 inSection:0]
を行うときに、それがnullを返していたときにところで、私はdidSelectRowAtIndexPath
でセルにアクセスすることができます。 didSelectRowAtIndexPath
で例えば
:
2012-03-17 01:38:47.125 x2516:207] TEST 1 - (null)
:私はセクション0に質問入力にたとえば「fooBar」を書いて、セクション4(ボタン「を掲載し」)でセルをクリックしたときに
if (indexPath.section==4) {
NSLog(@"TEST 1 - %@", ((AskCellQuestion *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]).questionText.text);
//[self askTheQuestion];
} else if (indexPath.section==0) {
NSLog(@"TEST 2 - %@", ((AskCellQuestion *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]).questionText.text);
NSLog(@"TEST 3 - %@", ((AskCellQuestion *)[tableView cellForRowAtIndexPath:indexPath]).questionText.text);
}
は、この出力を提供します
と私は質問入力を持つセルである、セクション0にあるセルをクリックしたときにこれを与える:
2012-03-17 01:38:44.782 x[2516:207] TEST 2 - fooBar
2012-03-17 01:38:44.793 x[2516:207] TEST 3 - fooBar
ありがとうございます...
うわー、私はそれを知らなかった。迅速な答えをありがとう! – berkersonmez