如果您正在为您的问题寻找其他解决方案,那么我建议您以编程方式创建一个自定义单元格。
我正在一步一步地向你解释,这将帮助你更好。
因此,为此创建一个继承自 UITableViewCell 的类,并在 tabelCell 中添加您需要的组件。
你的 .h 文件看起来像这样。
//--------开始-------->>
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell{
UIButton *btn1;
UIButton *btn2;
UIButton *btn3;
}
@property(nonatomic , retain) UIButton *btn1;
@property(nonatomic , retain) UIButton *btn2;
@property(nonatomic , retain) UIButton *btn3;
@end
//-------END-------
您的 .m 文件将如下所示
//--------开始-------->>
#import "CustomCell.h"
@implementation CustomCell
@synthesize btn1, btn2, btn3;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//----frame the components as per your project req.----
btn1 = [[UIButton alloc] initWithFrame:CGRectMake(1, 1, 85, 70)];
[self.contentView addSubview:btn1];
btn2 = [[UIButton alloc] initWithFrame:CGRectMake(100, 1, 85, 70)];
[self.contentView addSubview:btn2];
btn3 = [[UIButton alloc] initWithFrame:CGRectMake(195,1, 85, 70)];
[self.contentView addSubview:btn3];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
//--------END--------
现在您已准备好在其他类中重用此自定义单元格。也可以根据需要进行修改。
现在在 cellForRowAtIndexPath >>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
[cell.btN1 setImage:[UIImage imageNamed:@"YOUR IMAGE NAME"] forState:UIControlStateNormal]; // YOU CAN MAKE CHANGES HERE.
................// remaining logic goes here
return cell;
}
希望这会对您有所帮助。
1 .Also take a look on link tutorial.
2. A Closer Look at Table View Cells