2011-07-19 66 views
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // ... 
    PlanetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlanetCell_ID"]; 
    return cell; 
} 

如果你(在這種情況下PlanetTableViewCell)創建一個自定義的UITableViewCell是可以接受返回通過返回(UITableViewCell的*)方法,該方法的對象,或者是有別的東西,我應該做的事?cellForRowAtIndexPath返回自定義單元格?

回答

1

如果你(在這種情況下PlanetTableViewCell)創建一個自定義的UITableViewCell是可以接受返回通過返回(UITableView的*)方法,該方法的對象,或者是有別的東西,我應該做的事?

您可能意味着:

通過返回的方法(*的UITableViewCell)返回該對象,

如果是這樣的話,那是完全合法的,合理的。

事實上,你PlanetTableViewCellUITableViewCell被衍生的PlanetTableViewCell所有實例都也是類型UITableViewCell(is-a的OOP中的關係)。

+0

是的,我做到了,問題更新爲正確顯示UITableViewCell,謝謝。 – fuzzygoat

0

是的,這是返回單元格的正確方法。

但是你也應該檢查你的「出隊」是否返回一個有效的單元對象。如果沒有,你需要創建一個。

這種方法也是你應該標題,配件等

示例代碼來配置你的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // ... 
    PlanetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlanetCell_ID"]; 

    if (cell == nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    cell.titleLabel.text = @"Cell Title"; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    return cell; 
} 
0

使用自定義單元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier; 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     simpleTableIdentifier = @"dashboard_logintimeCell_ipad"; 
    } 
    else 
    { 
     simpleTableIdentifier = @"dashboard_logintimeCell"; 
    } 
    dashboard_logintimeCell *cell = (dashboard_logintimeCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib =[[NSBundle mainBundle]loadNibNamed:simpleTableIdentifier owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 
/*here you cell object get 
like 
[email protected]"yourlabeltext"; 
*/ 

    cell.backgroundColor=[UIColor clearColor]; 
    return cell; 
} 
相關問題