0

UITableViewController に問題があり、下にスクロールするとすぐにセルの背景画像のサイズが大きくなります。すべての画像は 320px の幅に設定されていますが、スクロールしてもセルの背景画像が拡大します。

ここに画像の説明を入力

なぜこれが起こっているのか、それを修正する方法を誰かが説明できますか?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (jsonResults.count == 0)
    {
        return 1;
    }
    else
    {
    return [jsonResults count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    UIImage *selectionBackground;
    UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];

    if (jsonResults.count == 0)
    {
        cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"topAndBottomRow.png"]
                                                                  stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];
        selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];
        [cell.selectedBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:selectionBackground]];
        cell.textLabel.text = @"Nothing was found :(";
        cell.detailTextLabel.text = @"Click here to add a venue!";
        //cell.textLabel.textColor= [UIColor colorWithRed:(79/255.0) green:(129/255.0) blue:(189/255.0) alpha:1] ;
        cell.textLabel.font = [UIFont fontWithName:@"Berlin Sans FB" size:22];
        cell.detailTextLabel.font = [UIFont fontWithName:@"Berlin Sans FB" size:14];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    else
    {
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    cell.userInteractionEnabled = YES;
    NSDictionary *venuesdict = [jsonResults objectAtIndex:indexPath.row];
    NSString *addresslineone = [venuesdict objectForKey:@"address1"];
    NSString *postcode = [venuesdict objectForKey:@"postcode"];
    NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
    NSInteger row = [indexPath row];
   if (row == 0 && row == sectionRows - 1)
   {
    //rowBackground = [UIImage imageNamed:@"topAndBottomRow.png"];
    cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"topAndBottomRow.png"]
                                                                 stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];
    selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];

    }
    else if (row == 0)
    {
        //rowBackground = [UIImage imageNamed:@"topRow.png"];
        cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"topRow.png"]
                                                                  stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
        selectionBackground = [UIImage imageNamed:@"topRowSelected.png"];


    }
    else if (row == sectionRows - 1)
    {
        //rowBackground = [UIImage imageNamed:@"bottomRow.png"];
        cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"bottomRow.png"]
                                                                  stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
        //rowBackground = [UIImage imageNamed:@"bottomRow.png"];

        selectionBackground = [UIImage imageNamed:@"bottomRowSelected.png"];


    }
    else
    {
        cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"middleRow.png"]
                                                                  stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
        //rowBackground = [UIImage imageNamed:@"middleRow.png"];
        selectionBackground = [UIImage imageNamed:@"middleRowSelected.png"];


    }
    UIImageView *imgView =  [[UIImageView alloc] initWithFrame:cell.selectedBackgroundView.frame];
    [imgView setImage:selectionBackground];
    [cell.selectedBackgroundView addSubview:imgView];
    [cell.selectedBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:selectionBackground]];
    cell.textLabel.text = [venuesdict objectForKey:@"name"];
    NSString *imagename = [venuesdict objectForKey:@"imagename"];
    cell.imageView.image = [UIImage imageNamed:imagename];
    cell.detailTextLabel.text = [NSString stringWithFormat:@" %@, %@",addresslineone,postcode];
    cell.textLabel.font = [UIFont fontWithName:@"Berlin Sans FB" size:22];
    cell.detailTextLabel.font = [UIFont fontWithName:@"Berlin Sans FB" size:10];
    cell.backgroundColor = [UIColor clearColor];
        NSString *version = [[UIDevice currentDevice] systemVersion];
        BOOL isAtLeast7 = [version floatValue] >= 7.0;
        if (!isAtLeast7 == YES)
        {
            cell.detailTextLabel.backgroundColor = [UIColor grayColor];
            cell.textLabel.backgroundColor = [UIColor grayColor];
        }

    }

    return cell;
    }
4

1 に答える 1