I saw there are lots of resources available on net regarding this question. I have to load a different XIB (UIViewContoller
) file for my cell. I have designed my cell looks there and I want to load that design in my cell.
I wrote this code but I am getting an exception.
-[UIView setTableViewStyle:]: unrecognized selector sent to instance 0x6040de0
2011-07-11 14:42:27.461 TableViewTest[2776:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setTableViewStyle:]: unrecognized selector sent to instance 0x6040de0'
And here is my code of loading nib file
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"loadXibfile" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
You should use UITableViewCell
and not UIView
in your XIB file.
Here is the solution and it is useful for me and home for you or some else may be.
cell = [[[YourCustomcell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];
NSArray *toplavelobject=[[NSBundle mainBundle]loadNibNamed:@"YourCustomcell" owner:self options:nil];
for(id c in toplavelobject)
{
if ([c isKindOfClass:[UITableViewCell class]])
{
cell=(YourCustomcell *) c;
break;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With