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