【问题标题】:custom cell not appear when loading new views objective-C加载新视图objective-C时不出现自定义单元格
【发布时间】:2012-08-07 14:51:58
【问题描述】:

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

}

【问题讨论】:

    标签: objective-c ios uitableview storyboard


    【解决方案1】:

    我认为你的问题在这里

    static NSString *CellIdentifier = @"CellIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    

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

    你用什么作为你的小区标识符?

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-02
        • 1970-01-01
        • 1970-01-01
        • 2020-04-25
        • 1970-01-01
        相关资源
        最近更新 更多