Reusing UITableViewCell which loaded from XIB

Discussion in 'iOS Programming' started by Sergio10, Mar 4, 2010.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hi,

    I have XIB bundle with UITableViewCell, UITable and UIView called "MyBundle".

    And I'd like to display cell loaded from XIB many times(reuse it).

    So I've created in UIViewController outlet of the cell, set Identifier and tried next code:
    PHP:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    [
    myCell prepareForReuse];

        return 
    myCell;
    }
    As result it shows only one cell. But it should be shown 10 items.

    I also tried next:
    PHP:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCellId"];

        if (
    cell == nil) {
            
    NSArray *nib = [[NSBundle mainBundleloadNibNamed:@"MyBundle" owner:self options:nil];
            
    cell = (UITableViewCell *)[nib objectAtIndex:0];
        }

        return 
    cell;
    }
    How to solve the problem?

    Thank you.
     
  2. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009

Share This Page