1

ストーリーボードで設計された静的セルを含む TableView があります。

コード内のセルの値を取得したい。

NSMutableArray* questions = [[NSMutableArray alloc] init];
for(int i=0; i<3; i++){
    SurveyCell* qCell = (SurveyCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:i]];
    SurveyCell* aCell = (SurveyCell*)[[self tableView] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:i]];
    NSString* question = qCell.label.text;
    NSString* answer = aCell.label.text;
    NSDictionary* questionObj = [[NSDictionary alloc] initWithObjectsAndKeys:question,@"question", answer,@"answer", nil];
    [questions addObject:questionObj];
}

ここで、qCell と aCell が null になることがあります。静的セルから値を取得する良い方法は何ですか?

4

0 に答える 0