我有一个包含 3 个部分和不同行的 uiTableView,我想将复选框添加到我的第三个部分,
我创建自定义单元格并链接 img 和标签
像这张照片:
![在此处输入图像描述][1]
我的自定义单元格代码是:
。H
: UITableViewCell
@property (strong, nonatomic) IBOutlet UIImageView *checkBox;
@property (strong, nonatomic) IBOutlet UILabel *absenceCode;
@end
.m
@synthesize checkBox;
@synthesize absenceCode;
- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
// Initialization code
checkBox.image = [UIImage imageNamed:@"emptycheck-box.png"];
}
return self;
}
@结尾
和 UITableViewController viewDidLoad 的代码
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *keys = [[NSMutableArray alloc] init];
NSMutableDictionary *contents = [[NSMutableDictionary alloc] init];
NSString *staKey = @"Start";
NSString *endKey = @"End";
NSString *absKey= @"Absence";
[contents setObject:[NSArray arrayWithObjects:@"Time: 08:00 Date: Fri,3 Aug, 2012", nil] forKey:staKey];
[contents setObject:[NSArray arrayWithObjects:@"Time: 17:57 Date: Fri,3 Aug, 2012", nil] forKey:endKey];
[contents setObject:[NSArray arrayWithObjects:@"Red",@"Black",@"Blue", nil] forKey:absKey];
[keys addObject:staKey];
[keys addObject:endKey];
[keys addObject:absKey];
[self setSectionKeys:keys];
[self setSectionContents:contents];
}
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = [[self sectionKeys] objectAtIndex:[indexPath section]];
NSArray *contents = [[self sectionContents] objectForKey:key];
NSString *contentForThisRow = [contents objectAtIndex:[indexPath row]];
CheckBoxTableViewCell *cell = (CheckBoxTableViewCell*)[tableView
dequeueReusableCellWithIdentifier:@"CheckBoxTableViewCell"];
cell.imageView.image=[UIImage imageNamed:@"emptycheck-box.png"];
cell.checkBox.image = image;
cell.absenceCode.text =@"Redddd";
cell.text =contentForThisRow;
return cell;
}
请你帮我提前谢谢!