私はtableViewを持っていますが、テーブルビューのcell.the textlabelが重なって表示されています。スクリーンショットとコードです。テーブルビューのセルがクリックされたデータが重なって表示される
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary *boy=[self.media1 objectAtIndex:indexPath.row];
NSString *str=[[NSString alloc]initWithFormat:@"%@",boy];
NSInteger n=[str intValue];
NSLog(@"the value:%@",str);
if(n ==0)
{
CGRect starFrame = CGRectMake(217,6, 85, 40);
UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
starImage.image = [UIImage imageNamed:@"nostar.png"];
starImage.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:starImage];
NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
CGRect labelFrame = CGRectMake(203,18, 20, 20);
UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
Label.text=boo;
[cell.contentView addSubview:Label];
}
if(n >=1)
{
CGRect starFrame = CGRectMake(217,6, 85, 40);
UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
starImage.image = [UIImage imageNamed:@"1star.png"];
[cell.contentView addSubview:starImage];
NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
CGRect labelFrame = CGRectMake(203,18, 20, 20);
UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
Label.text=boo;
[cell.contentView addSubview:Label];
}
if(n >=2)
{
CGRect starFrame = CGRectMake(217,6, 85, 40);
UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
starImage.image = [UIImage imageNamed:@"twostar.png"];
[cell.contentView addSubview:starImage];
NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
CGRect labelFrame = CGRectMake(203,18, 20,20);
UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
Label.text=boo;
[cell.contentView addSubview:Label];
}
if(n >=3)
{
CGRect starFrame = CGRectMake(217,6, 85, 40);
UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
starImage.image = [UIImage imageNamed:@"threestar.png"];
[cell.contentView addSubview:starImage];
NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
CGRect labelFrame = CGRectMake(203,18, 20,20);
UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
Label.text=boo;
[cell.contentView addSubview:Label];
}
if(n >= 4)
{
CGRect starFrame = CGRectMake(217,6, 85, 40);
UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
starImage.image = [UIImage imageNamed:@"4star.png"];
[cell.contentView addSubview:starImage];
NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
CGRect labelFrame = CGRectMake(203,18,20,20);
UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
Label.text=boo;
[cell.contentView addSubview:Label];
}
if(n >= 5)
{
CGRect starFrame = CGRectMake(217,6, 85, 40);
UIImageView *starImage = [[[UIImageView alloc] initWithFrame:starFrame] autorelease];
starImage.image = [UIImage imageNamed:@"5star.png"];
[cell.contentView addSubview:starImage];
NSString *boo=[[NSString alloc]initWithFormat:@"%d",n];
CGRect labelFrame = CGRectMake(203,18, 20,20);
UILabel *Label = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
Label.text=boo;
[cell.contentView addSubview:Label];
}
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text=[self.story objectAtIndex:indexPath.row];
cell.textLabel.numberOfLines=2;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
title=[self.story objectAtIndex:indexPath.row];
NSDictionary *detaildesc1=[self.descriptiondesc objectAtIndex:indexPath.row];
FirstViewDetailDetail *detailViewController1 = [[FirstViewDetailDetail alloc] initWithItem:detaildesc1 Title:title];
[self.navigationController pushViewController:detailViewController1 animated:YES];
[detailViewController1 release];
}
ワンノートのほかに:あなたは 'N> = '1'、 'N> = 2'などをチェックしているので、あなたはまた、句場合は、他のすべてを実行している5つ星のためにこのよう
'switch'ステートメントを使用すると、これを高速化できます。私は重ね合わされた数を助けることができない。 –