加载新视图objective-C时不显示自定义单元格

时间:2012-08-10 09:59:02

标签: objective-c ios uitableview storyboard

我以编程方式创建一个UITableView,其中包含连接到storyboard中其他视图的不同单元格和部分

但是,如果您检查故事板缺席视图是否包含自定义单元格,其复选框部分未显示在此处

我的问题是:

为什么它没有显示自定义单元格?,请你帮我

提前致谢!

这是我的代码:

- (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];

}

2 个答案:

答案 0 :(得分:0)

我认为你的问题在这里

static NSString *CellIdentifier = @"CellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

您的自定义单元格应具有唯一的单元格标识符。您需要将该唯一的单元格标识符传递给-dequeueReusableCellWithIdentifier:

您使用了什么作为细胞标识符?

答案 1 :(得分:0)

你应该使用NSLOG来确保你会看到不同的观点,我认为你总是在同一个观点中是你看不到新变化的原因