0

ねえ、私はビジネスファインダースタイルのアプリを作成しようとしていて、ユーザーに情報を表示するためのカスタムセルを作成したいと思っていました。提供しようとしているすべての情報を表示するセルがありますが、形式がオフになっています。これが私がセルを作成するために使用しているコードです。

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellView" owner:self options:nil];

#ifdef __IPHONE_2_1
        cell = (CustomCell *)[nib objectAtIndex:0];
#else
        cell = (CustomCell *)[nib objectAtIndex:1];
#endif
    }

    // Configure the cell.
    NSDictionary *dict = [rows objectAtIndex: indexPath.row];

    cell.bizNameLabel.text = [dict objectForKey:@"name"];
    cell.addressLabel.text = [dict objectForKey:@"address"];

    NSMutableString *detailed = [NSMutableString string];
    [detailed appendString:[dict objectForKey:@"distance"]];
    [detailed appendString:@"mi"];
    cell.mileageLabel.text = detailed;

    // determine the rating for the business
    NSString *icontype = [dict objectForKey:@"rating"];
    NSInteger rating = [icontype intValue];
    UIImage *image;
    // variable to change the color of the cell's background
    UIView *bg = [[UIView alloc] initWithFrame:cell.frame];

    // switch statement to determine the rating image to be displayed
    switch (rating) {
        case 1:
        {
            image = [UIImage imageNamed:@"1.png"];
            bg.backgroundColor = [UIColor yellowColor]; 
            break;
        }
        case 3:
        {
            image = [UIImage imageNamed:@"3.png"];
            bg.backgroundColor = [UIColor orangeColor]; 
            break;
        }
        case 5:
        {
            image = [UIImage imageNamed:@"5.png"];
            //bg.backgroundColor = [UIColor redColor]; 
            cell.backgroundColor = [UIColor redColor];
            break;
        }
        default:
            break;
    }

    [cell.ratingImage setImage:image];
    cell.backgroundView = bg;
    [bg release];


#ifdef __IPHONE_3_0
    cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
#endif

    return cell;
}

次に、IBで次のようなレイアウトを作成しました。

(最初の2つの問題は解決されました。画像を表示するために、間違った画像変数を使用していました)

そして、選択すると、物事がうまくいかないことがわかります

![ここに画像の説明を入力してください] [3]

IBでは、セルのサイズを幅320×高さ80に設定し、[インデント]タブでクラスをCustomClassに変更しました。些細なことを見落としていると思いますが、誰かが私に骨を投げてくれたらありがたいです。画像が希望の場所に表示されないという問題を修正しましたが、背景色が変わらず、フォントサイズが異なって表示され、セルを選択するとセルセパレーターと重なるという問題が発生します。 。

注:スクリーンショットを含めようとしましたが、私は新しいので、SOは私を許可しませんでした。下のセパレーターと重なる選択したセルの画像を配置したリンクを提供しました。

http://s1216.photobucket.com/albums/dd361/cabearsfan/?action=view¤t=screenshot2.png

4

2 に答える 2

0

UIImageViewのnib参照を使用していないようですが、セルのデフォルトのimageViewプロパティを使用しています。

于 2011-05-27T20:34:25.003 に答える
0

imageviewフレームと提供する画像のサイズが一致していないと思います。

setImageを呼び出した後、次のコードを追加して、何が起こっているかを調べます。

NSLog(@" imageView frame %f,%f, %f, %f",imageView.frame.origin.x,imageView.frame.origin.y,
    imageView.frame.size.width,imageView.frame.size.height);
NSLog(@" image  size %f x %f", image.size.width, image.size.height);
于 2011-05-27T20:36:30.587 に答える