UITableView自定义单元格未显示核心数据

时间:2013-11-01 15:45:48

标签: ios uitableview

我让表格单元格正确显示数据,但随后创建了一个自定义单元格和类,以便我可以更好地控制布局...但我无法获取自定义单元格以显示数据..只显示带有占位符文字的标签......我缺少什么?

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.results.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellResults";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    ResultsCell *resultscell = (ResultsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NSManagedObject *result = [self.results objectAtIndex:indexPath.row];


    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MMMM dd, yyyy"];
    [dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
    NSString *eventDate = [dateFormatter stringFromDate:[self trialDate]];

    // formatting
    resultscell.labelEventDesc.numberOfLines = 0;

    //  populate the cells
    [resultscell.labelEventDesc setText:[NSString stringWithFormat:@"%@",[result valueForKey:@"eventdesc"]]];
    [resultscell.labelWeeksOut setText:[NSString stringWithFormat:@"%@",[result valueForKey:@"weeksout"]]];
    [resultscell.labelEventDate setText:[NSString stringWithFormat:@"%@",eventDate]];
    return cell;
}

1 个答案:

答案 0 :(得分:1)

您正在创建2个不同的单元格实例(cellresultscell),配置一个并返回另一个。所以你的自定义类实例永远不会用于任何事情。

卸下:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

并将return cell;更改为return resultscell;