ロードUITabelView
するviewDidLoad
とセルに適切なデータが表示されませんが、テーブルビューをスクロールすると適切なデータが設定されます。私のコードで何が問題になっていますか?
ここで私が使用するコード。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [_AnswerKeyTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for(id currentObject in topLevelObject)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CustomCell*)currentObject;
}
}
}
ModelInfo *info = [mArray objectAtIndex:indexPath.row];
CGSize constraint = CGSizeMake(212, 20000.0f);
NSString *temp=[NSString stringWithFormat:@"%@ (%@)",info.your_answer,info.answer_status];
CGSize question_size = [info.question sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGSize your_answer_size = [temp sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGSize correct_answer_size = [info.correct_answer sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
NSString * ans_string;
if([info.answer_status isEqualToString:@"Correct answered"])
{
ans_string = [NSString stringWithFormat:@"%@(<font color=\"#7EBA00\"><b>%@</b></font>)",info.your_answer,info.answer_status];
cell.lblCorrectAnswer.hidden = YES;
cell.lblC_Ans.hidden = YES;
}else if([info.answer_status isEqualToString:@"Not answered"]){
ans_string = [NSString stringWithFormat:@"<font color=\"#FF0000\"><b>%@</b></font>)",info.answer_status];
cell.lblCorrectAnswer.hidden = NO;
cell.lblC_Ans.hidden = NO;
cell.lblCorrectAnswer.text =info.correct_answer;
[cell.lblCorrectAnswer setFrame:CGRectMake(103,your_answer_size.height+question_size.height+9,212,correct_answer_size.height)];
[cell.lblC_Ans setFrame:CGRectMake(cell.lblC_Ans.frame.origin.x,your_answer_size.height+question_size.height+9,cell.lblC_Ans.frame.size.width,21)];
}else{
ans_string = [NSString stringWithFormat:@"%@(<font color=\"#FF0000\"><b>%@</b></font>)",info.your_answer,info.answer_status];
cell.lblCorrectAnswer.hidden = NO;
cell.lblC_Ans.hidden = NO;
cell.lblCorrectAnswer.text =info.correct_answer;
[cell.lblCorrectAnswer setFrame:CGRectMake(103,your_answer_size.height+question_size.height+9,212,correct_answer_size.height)];
[cell.lblC_Ans setFrame:CGRectMake(cell.lblC_Ans.frame.origin.x,your_answer_size.height+question_size.height+9,cell.lblC_Ans.frame.size.width,21)];
}
cell.lblQuestion.text = info.question;
cell.lblYourAnswer.text = ans_string;
cell.lblYourAnswer.attributedText=[OHASBasicHTMLParser attributedStringByProcessingMarkupInAttributedString:cell.lblYourAnswer.attributedText];
cell.lblQue.text = [NSString stringWithFormat:@"Question %d",indexPath.row+1];
[cell.lblQuestion setFrame:CGRectMake(103, 3,212,question_size.height)];
[cell.lblYourAnswer setFrame:CGRectMake(103,cell.lblQuestion.frame.size.height+6,212,your_answer_size.height)];
[cell.lblAns setFrame:CGRectMake(cell.lblAns.frame.origin.x,cell.lblQuestion.frame.size.height+6,cell.lblAns.frame.size.width,21)];
[cell.view setFrame:CGRectMake(5,1,310,cell.lblQuestion.frame.size.height+cell.lblYourAnswer.frame.size.height+cell.lblCorrectAnswer.frame.size.height)];
[cell setFrame:CGRectMake(0,0,320,cell.view.frame.size.height)];
[cell setFrame:CGRectMake(0,0,320,cell.frame.size.height+10)];
return cell;
}