【发布时间】:2014-01-17 02:46:49
【问题描述】:
我是 iPhone 开发新手,对原型单元有疑问。 在我的故事板中,我有导航控制器。我用视图控制器(作为主窗口)推动它,它有一个按钮,当我点击它时,我用自定义原型单元打开 tableView 控制器
- (IBAction)searchClick:(id)sender {
CNCarTableController *car = [[CNCarTableController alloc]init];
[self.navigationController pushViewController:car animated:TRUE];
}
但是当它打开时它有空行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: ( NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TransportCell";
CNTransportCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if(cell == nil){
cell = [[CNTransportCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//cell.textLabel.text = @"bmv";
cell.name = (UILabel*) [cell viewWithTag:100];
[cell.name setText:@"a text"];
cell.number.text = @"number";
cell.car.text = @"car";
return cell;
}
但如果使用cell.textLabel.text = @"bmv"; 一切正常。但是对于带有标签或 cell.lbl.text 的自定义单元格方式不起作用。那里有什么问题?它可以是带有视图控制器的导航控制器的细微差别吗?
自定义单元格代码:
@interface CNTransportCell : UITableViewCell
@property (nonatomic,weak) IBOutlet UILabel *name;
@property (nonatomic,weak) IBOutlet UILabel *number;
@property (nonatomic,weak) IBOutlet UILabel *car;
@结束
@implementation CNTransportCell
@synthesize name;
@synthesize number;
@synthesize car;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
【问题讨论】:
-
您是如何制作自定义单元格的?
-
@amar 我贴的是custum cell的代码,Indentifier是TransportCell
标签: ios iphone ios5 storyboard