Reputation: 183
In my app I was in the process of changing a UITableView from being added programmatically to being added by a XIB. Decided to scratch the idea and go back but now the app is crashing with
message:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "TableViewController" nib but didn't get a UITableView.'
I was reading elsewhere on SO that I should go back and delete connections from the NIB but I already deleted the NIB file! So any suggestions please?
//ViewController.h
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController <UITableViewDelegate,
UITableViewDataSource, UIAlertViewDelegate>
@property (nonatomic) CGFloat rowHeight;
@property (nonatomic, retain) NSManagedObjectContext *context;
@property (nonatomic, retain) NSMutableArray *arr;
@end
//ViewController.m
#import "TableViewController.h"
#import "AddNewExViewController.h"
#import "Exercises.h"
#import "DetailViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController
@synthesize context, arr;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
self.title = @"Exercises";
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercises"
inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setFetchBatchSize:20];
[request setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSArray *newArray = [NSArray arrayWithObject:sort];
[request setSortDescriptors:newArray];
NSError *error;
NSMutableArray *results = [[context executeFetchRequest:request error:&error] mutableCopy];
[self setArr:results];
[self.tableView reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteAll)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
self.tableView.rowHeight = 60.f;
}
Edit:
//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
TableViewController *table = [[TableViewController alloc] init];
table.context = self.managedObjectContext;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:table];
/*nav.toolbarHidden = NO;*/ //uncomment if you want a tool bar at bottom of tableView
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Upvotes: 0
Views: 322
Reputation: 1625
How do you init this controller ? Is it the only controller in the program ? If so please post some code on Appdelegate didfinishloadingwithoptions
*Edit
do a clean up of your project (xcode > project menu > clean) and reset your simulator & see if problem persists. also make sure your code reaches initWithStyle method in TableViewController by putting a breakpoint there.
Upvotes: 1