0

テーブルセルにデータを正しく表示させましたが、レイアウトをより細かく制御できるようにカスタムセルとクラスを作成しました...しかし、カスタムセルにデータを表示させることはできません..プレースホルダー テキスト付きのラベル...何が欠けているのでしょうか?

#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;
}
4

1 に答える 1

1

2 つの異なるセル インスタンス (cellおよびresultscell) を作成し、1 つを構成してもう 1 つを返します。したがって、カスタム クラスのインスタンスが実際に使用されることはありません。

削除する:

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

に変更return cell;return resultscell;ます。

于 2013-11-01T15:47:55.087 に答える