我正在试着用定制的单元格制作一个表格视图。
我已经创建了两个引用我的类CustomCell的文件.m和.h。代码如下:
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
{
IBOutlet UIImageView *miniLogo;
IBOutlet UILabel *cellText;
IBOutlet UIButton *deleteButton;
}
@property (strong, nonatomic) IBOutlet UIImageView *miniLogo;
@property (strong, nonatomic) IBOutlet UILabel *cellText;
@property (strong, nonatomic) IBOutlet UIButton *deleteButton;
@end
-------------------------------------------------------------
#import "CustomCell.h"
@implementation CustomCell
@synthesize miniLogo,cellText, deleteButton;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
}
/*
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}*/
@end
使用.xib文件,我设计了我的单元,连接了IBOutlets并设置了单元的标识符。
在包含自定义单元格的表中,我调用方法tableView:cellForRowAtOndexPath中的单元格,如下所示:
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellsIdentifier ];
if (cell == nil){
UIViewController *tempVC = [[UIViewController alloc] initWithNibName:@"CustomCell" bundle:nil];
cell = (CustomCell *)tempVC.view;
}
当我启动我的应用程序时,标签显示文本集,图像视图显示正确的图像。但是按钮没有出现。事实上,当设置断点时,我发现我的按钮地址总是0x00000000 (意味着我的按钮没有启动)。
有人能帮我解决这个问题吗?
发布于 2013-05-23 15:19:16
我找到了问题所在。
在他的viewDidLoad中,我正在做:
UINib *cellNib = [UINib nibWithNibName:@"myCells" bundle:nil];
[self.tableView registerNib:cellNib forCellReuseIdentifier:CellsIdentifier];
但是因为我更改了我的.xib名称,所以我没有加载正确的接口。奇怪的是,我没有任何名为"myCells“的笔尖。也许我应该在我的项目上进行一次“整洁”。
https://stackoverflow.com/questions/16696442
复制相似问题