4つのラベルでセルをカスタマイズしましたが、最初はうまく見えますが、スクロールして別の行のセルラベルを選択するとオーバーラップします。ここに私のコードです。どんな助力も高く評価されます。カスタムセルオーバーラップのラベル
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *[email protected]"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: CellIdentifier] autorelease];
}
NSString *cellIconName = [[self cellIcon] objectAtIndex:[indexPath row]];
cellImage=[UIImage imageNamed:cellIconName];
cell.imageView.image=cellImage;
UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(65, 10, 140, 20)];
labelOne.text = [[NSString alloc]initWithFormat:@"%@",[dataList objectAtIndex:indexPath.row]];
[cell.contentView addSubview:labelOne];
[labelOne release];
UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(260, 10, 140, 20)];
labelTwo.text = [[NSString alloc]initWithFormat:@"%@",[newPrice objectAtIndex:indexPath.row]];
[cell.contentView addSubview:labelTwo];
[labelTwo release];
UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(65, 30, 140, 20)];
label3.text=[[NSString alloc]initWithFormat:@"%@",[details objectAtIndex:indexPath.row]];
[cell.contentView addSubview:label3];
[label3 release];
UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(260, 30, 140, 20)];
label4.text=[[NSString alloc]initWithFormat:@"%@",[oldPrice objectAtIndex:indexPath.row]];
[cell.contentView addSubview:label4];
[label4 release];
return cell;
}
このコードは、問題のコードよりも優れているなぜあなたはそれがだろう、説明してもらえまた、この次のコードスニペットを試すことができますこの答をアップヴォートの価値があるものにする。 – jrturton
それは動作します...あなたは私のコードで何が間違っているか説明できますか? – NoviceDeveloper
Mr.NoviceDeveloperとMr.Jrturton。間違いはif条件(if cell(== nil))の外で(else部分)のラベルを割り当てたことです。コードを実行すると、コントロールはセルがnilであるかどうか、または値があるかどうかをチェックします。毎回else部分にラベルを割り当てると(スクロール中も)、ラベルは配列から値を割り当てて取得します。 if条件で割り当てると、ラベルが各セルに割り当てられ、配列から値が取得されるだけです。私の貧しい英語のために申し訳ありません。明らかです?ありがとう。 –