我以编程方式创建了一个包含不同部分的表格视图控制器我想在我的第三部分中添加 3 行带有复选标记框(我使用了故事板!)请你给我一些提示,我该怎么做..
我的问题是如何在左侧为我的第三部分设置复选框
这是图片:而不是请设置您的代码:在缺席代码部分中有 3 行带有复选标记框
这是我在故事板中的观点:
这是代码:
- (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:@"Please set your code", nil] forKey:absKey];
[keys addObject:staKey];
[keys addObject:endKey];
[keys addObject:absKey];
[self setSectionKeys:keys];
[self setSectionContents:contents];
}
- (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]];
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
[[cell textLabel] setText:contentForThisRow];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSMutableArray *weekArray = [[ NSMutableArray alloc] initWithObjects: @"Start Time", @"End Time",@"Absence Code",
nil];
return [weekArray objectAtIndex:section];
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath:(NSIndexPath
*)indexPath {
return UITableViewCellAccessoryDisclosureIndicator;
}
提前致谢!