【发布时间】:2011-05-26 14:41:28
【问题描述】:
我正在尝试创建一个包含单个大按钮的 UITableViewCell。
我尝试了看起来很明显的方法,将 UIButton 添加到单元格的 contentView,但它不起作用(单元格显示为空)。我哪里错了?
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"startButtonCell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"startButtonCell"] autorelease];
UIButton *btn = [[UIButton alloc] initWithFrame:cell.contentView.bounds];
[cell.contentView addSubview:btn];
if (!self.task.isCompleted) {
btn.titleLabel.text = @"Start!";
}else{
btn.titleLabel.text = @"Continue!";
}
[btn release];
}
【问题讨论】:
-
我假设这是您的
-cellForRowAtIndexPath:实现...您确定您的代码执行超过if (cell == nil) {吗?按钮的大小是否正确创建?你能提供完整的-cellForRowAtIndexPath:吗?
标签: cocoa-touch uitableview uibutton