2013-11-01 167 views
0

我有表格單元格顯示正確的數據,但後來做了一個自定義單元格和類,以便我可以更多地控制佈局......但我無法獲得我的自定義單元格顯示數據..它只是顯示標籤與他們的佔位符文本...我錯過了什麼?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

您要創建2個不同的單元例(cellresultscell),配置一個並返回等。所以你的自定義類實例從來不用於任何事情。

刪除:

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

,改變return cell;return resultscell;

+0

現貨!令人驚訝的是,你如何看待一段代碼永遠只需要另一雙眼睛就能看到明顯的東西。非常感謝...完美的作品。 – Mark