【发布时间】:2014-03-17 17:42:36
【问题描述】:
所以这是我的代码,它不起作用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier;
if (indexPath.row == 0)
{
// buttonCell
CellIdentifier = @"buttonCell";
buttonCell *cell = (buttonCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.startAddressLabel.text = @"something";
//cell config
//debug
NSLog(@"indexPath.row: %d", indexPath.row);
NSLog(@"Cell Identifier: %@", CellIdentifier);
return cell;
} else if (indexPath.row == 1)
{
//mutableCaptionCell date&time
CellIdentifier = @"mutableCaptionCell";
mutableCaptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//cell config
cell.infoLabel.text = @"Время и дата";
cell.contentLabel.text = @"";
//debug
NSLog(@"indexPath.row: %d", indexPath.row);
return cell;
} else if (indexPath.row == 2)
{
//mutableCaptionCell tax
CellIdentifier = @"mutableCaptionCell";
mutableCaptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//cell config
cell.infoLabel.text = @"Тариф";
cell.contentLabel.text = @"";
//debug
NSLog(@"indexPath.row: %d", indexPath.row);
return cell;
} else if (indexPath.row == 3)
{
//mutableCaptionCell car
CellIdentifier = @"mutableCaptionCell";
mutableCaptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//cell config
cell.infoLabel.text = @"Выбор машины на карте";
cell.contentLabel.text = @"";
//debug
NSLog(@"indexPath.row: %d", indexPath.row);
return cell;
} else if (indexPath.row == 4)
{
//wishCell wishlist
CellIdentifier = @"wishCell";
WishCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//cell config
cell.infoLabel.text = @"Пожелания";
cell.contentLabel.text = @"";
//debug
NSLog(@"indexPath.row: %d", indexPath.row);
return cell;
} else
{
//debug
NSLog(@"indexPath.row: %d", indexPath.row);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mutableCaptionCell" forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = @"ERROR CELL";
//debug
//NSLog(@"indexPath.row: %d", indexPath.row);
return cell;
;
}
}
我已经为每个原型说过 UITableViewCell 的子类,重用标识符与每个原型匹配,但我在运行时看到的 UITableView 似乎没有使用这些原型。例如,第一个单元格必须很大,有两个按钮,但它显示为空。我 NSLoged 一切,并记录显示:
2014-02-18 10:13:51.587 app[1624:70b] indexPath.row: 0
2014-02-18 10:13:51.590 app[1624:70b] Cell Identifier: buttonCell
2014-02-18 10:13:51.594 app[1624:70b] cell: <buttonCell: 0x8b95e00; baseClass = UITableViewCell; frame = (0 0; 320 44); autoresize = W; layer = <CALayer: 0x8b96000>>
2014-02-18 10:13:51.600 app[1624:70b] indexPath.row: 1
2014-02-18 10:13:51.603 app[1624:70b] indexPath.row: 2
2014-02-18 10:13:51.606 app[1624:70b] indexPath.row: 3
2014-02-18 10:13:51.610 app[1624:70b] indexPath.row: 4
但 TableView 仍然没有使用正确的原型。
我正在尝试使用动态原型,因为我需要在运行时更改一些单元格高度,可能有一种方法可以使用静态单元格吗?
旁注:我在 iOS 7 上使用 Xcode 5
【问题讨论】:
标签: ios uitableview