加载新视图objective-C时不出现自定义单元格 [英] custom cell not appear when loading new views objective-C

查看:33
本文介绍了加载新视图objective-C时不出现自定义单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I create a UITableView programmatically with different cells and sections that connects to the other views in 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];

}

推荐答案

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

you should use NSLOG to be sure that you are going to different views, I think you are always in a same view is the reason that you cann't see the new changes

这篇关于加载新视图objective-C时不出现自定义单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆