0

我以编程方式创建了一个 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];

}
4

2 回答 2

0

我认为你的问题在这里

static NSString *CellIdentifier = @"CellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

你用什么作为你的手机标识符?

于 2012-08-10T12:06:14.920 回答
0

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

于 2012-08-13T06:34:32.853 回答