Reputation:
I have a custom UITableViewCell which links to a UITableVIewCell xib. When I run the app, I get an error.
I did a lot of searching and I came up with this. When I try dragging from the cells view to the file owner, it seems like the view is not clickable, or drag-able.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CategorieUITableVIewCell"];
if (cell == nil) {
UIViewController *tempVC = [[UIViewController alloc] initWithNibName:@"CategorieUITableVIewCell" bundle:nil];
cell = (CategorieUITableVIewCell *)tempVC.view;
}
return cell;
}
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "CategorieUITableVIewCell" nib but the view outlet was not set.'
Not sure if this is clear enough, but if you have any questions, please ask.
Upvotes: 1
Views: 653
Reputation: 211
This will work for SURE. You can try this in cellForRowAtIndexPath method.
static NSString *categoryTableIdentifier = @"CategoryUITableViewCell";
CategoryUITableViewCell *cell = (CategoryUITableViewCell *)[tableView dequeueReusableCellWithIdentifier: categoryTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CategoryUITableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.CustomedLabel.text=[YourArray objectAtIndex:indexPath.row];
return cell;
And IMPORTANT thing to note is in your Custom cell class you will have to connect the outlet to "Table View Cell" and not the "File's Owner" when you are working with Custom Cell
Upvotes: 2
Reputation: 676
Please check the identifier matches with the one you specified in your xib. And then just replace your
if (cell == nil) {
UIViewController *tempVC = [[UIViewController alloc] initWithNibName:@"CategorieUITableVIewCell" bundle:nil];
cell = (CategorieUITableVIewCell *)tempVC.view;
}
code to
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"CategorieUITableVIewCell" owner:nil options:nil] objectAtIndex:0];
}
Upvotes: 0