1

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.

Community
  • 1
  • 1
  • check that r u assign the name of cell class **CategorieUITableVIewCell** – Anbu.Karthik Feb 02 '15 at 05:31
  • I don't know where you searched, but this is not the recommended way to do it any more. You should register the nib (in viewDidLoad is a good place), and get rid of the if cell == nil clause. – rdelmar Feb 02 '15 at 06:36
  • goto CategorieUITableVIewCell.xib--> "Show the identity inspector"-->custom class then check you class name – Hardik Kardani Feb 02 '15 at 08:49

3 Answers3

2

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

Rahul
  • 211
  • 2
  • 18
  • 1
    Man, this was driving me crazy. I've been using storyboard since it appeared and I forgot to use xibs cells properly. My problem was the outlet connection. I usually tend to drag from IB to the class but that connects it to the File's Owner instead the cell. THANK YOU!! – rmvz3 Sep 04 '15 at 02:18
0

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];
}
Tejvansh
  • 676
  • 4
  • 9
0

Check cell identifier and class name in xib.

Girish Kolari
  • 2,515
  • 2
  • 24
  • 34