0
我有這個頁面,每個單元格都不一樣,所以我這樣做就像下面的代碼,但不知何故,我相信它可以優化,任何想法,我應該使用自定義單元格,但如果是的,那麼我有創建12個定製單元,因爲每個單元都有完全不同的佈局Uitableview不同的單元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// }
if (indexPath.row==0)
{
UILabel *lbl_label = [[UILabel alloc] initWithFrame:CGRectMake(15, 7, 200, 25)];
lbl_label.text = @"PRICE";
[lbl_label setFont:NORMAL_LABEL(16)];
[lbl_label setTextColor:UIColorFromRGB(0x565A5C,1.0)];
UILabel *lbl_price = [[UILabel alloc] initWithFrame:CGRectMake(100, 7, 200, 25)];
lbl_price.text = @"$ 50";
[lbl_price setFont:NORMAL_LABEL(16)];
[lbl_price setTextColor:[UIColor grayColor]];
[lbl_price setTextColor:UIColorFromRGB(0x82898D,1.0)];
lbl_price.textAlignment = NSTextAlignmentRight;
[cell addSubview:lbl_price];
[cell addSubview:lbl_label];
}
else if (indexPath.row==1)
{
UILabel *lbl_label = [[UILabel alloc] initWithFrame:CGRectMake(15, 7, 200, 25)];
lbl_label.text = @"CUISINE";
[lbl_label setFont:NORMAL_LABEL(16)];
[lbl_label setTextColor:UIColorFromRGB(0x565A5C,1.0)];
UILabel *lbl_price = [[UILabel alloc] initWithFrame:CGRectMake(100, 7, 200, 25)];
lbl_price.text = @"Sushi, Japanese, Arabian";
[lbl_price setFont:NORMAL_LABEL(16)];
[lbl_price setTextColor:[UIColor grayColor]];
[lbl_price setTextColor:UIColorFromRGB(0x82898D,1.0)];
lbl_price.textAlignment = NSTextAlignmentRight;
[cell addSubview:lbl_price];
[cell addSubview:lbl_label];
}
else if (indexPath.row==2)
{
UILabel *lbl_label = [[UILabel alloc] initWithFrame:CGRectMake(15, 7, 200, 25)];
lbl_label.text = @"GOOD FOR";
[lbl_label setFont:NORMAL_LABEL(16)];
[lbl_label setTextColor:UIColorFromRGB(0x565A5C,1.0)];
UILabel *lbl_price = [[UILabel alloc] initWithFrame:CGRectMake(100,7, 200, 25)];
lbl_price.text = @"Alcohol, Brunch";
[lbl_price setFont:NORMAL_LABEL(16)];
[lbl_price setTextColor:[UIColor grayColor]];
[lbl_price setTextColor:UIColorFromRGB(0x82898D,1.0)];
lbl_price.textAlignment = NSTextAlignmentRight;
[cell addSubview:lbl_price];
[cell addSubview:lbl_label];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}