我以编程方式创建了一个 UITableView,其中包含连接到情节提要中其他视图的不同单元格和部分
但是,如果您检查故事板缺席视图具有带有复选框部分的自定义单元格,则它不会出现在此处
我的问题是:
为什么它不显示自定义单元格?,你能帮我吗?
提前致谢!
这是我的代码:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString: @"WorkTime"]){
[segue.destinationViewController setTitle:@"WorkTime"];
}if([segue.identifier isEqualToString: @"Absence"]){
[segue.destinationViewController setTitle:@"Absence"];
}if([segue.identifier isEqualToString: @"Compensation"]){
[segue.destinationViewController setTitle:@"Compensation"];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *keys = [[NSMutableArray alloc] init];
NSMutableDictionary *contents = [[NSMutableDictionary alloc] init];
NSString *workKey = @"work";
NSString *absKey = @"absence";
NSString *comKey = @"compensation";
[contents setObject:[NSArray arrayWithObjects:@"Work Time", nil] forKey:workKey];
[contents setObject:[NSArray arrayWithObjects:@"Absence", nil] forKey:absKey];
[contents setObject:[NSArray arrayWithObjects:@"Compensation", nil] forKey:comKey];
[keys addObject:workKey];
[keys addObject:absKey];
[keys addObject:comKey];
[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;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedIndex = indexPath.row;
[self.tableView reloadData];
//case1
[self performSegueWithIdentifier:@"WorkTime" sender:self];
//case2
[self performSegueWithIdentifier:@"Absence" sender:self];
//case3
[self performSegueWithIdentifier:@"Compensation" sender:self];
}