More than one user cell with the same XIB

Is it possible to have more than one custom uitableviewCell inside the same xib?

I am trying to save XIB files by combining different custom cells within the same xib and then loading different tables from it.

In IB, I tried to set each of the uiTableViewCell classes to a different implementation of the custom class .m / .h. Here is what I tried:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *cellIdentifier = @"DevConfigCell";

DeviceInfoCell *cell = (DeviceInfoCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if(cell == nil)
{

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell~iphone" owner:self options:nil];
    cell = ( DeviceInfoCell *)[nib objectAtIndex:0];

}

return cell;
}

In another table, I would reuse nib, but I would do the following:

    cell = ( SecondDeviceInfoCell *)[nib objectAtIndex:0];

For some reason, it always loads the first cell.

Should all this work? or is there a way?

thank

+5
source share
2 answers

I am trying to save XIB files by combining different custom cells within the same xib

? .xib, .

.

.xib, , , . 10 .xib, .xib, 10 . , , . .xibs, , .

cell = ( SecondDeviceInfoCell *)[nib objectAtIndex:0];

, , , . , - . , [nib objectAtIndex:0], , nib . Casting , ; .

IBOutletCollection ; , objectAtIndex:. , , , .

+3
   NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"PlayerAvgsTableCell" owner:nil options:nil];
    for(id currentObject in topLevelObjects)
    {
        if([currentObject isKindOfClass:[PlayerAvgsTableCell class]])
        {
            cell = (PlayerAvgsTableCell *)currentObject;
            break;
        }
    }
}
0

All Articles