在我的应用程序中,我正在将UITableView更改为以编程方式添加到由XIB添加。决定抓住这个想法然后回去,但现在应用程序崩溃了
消息:由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:' - [UITableViewController loadView]加载了" TableViewController" nib但没有得到UITableView。'
我正在其他地方阅读,我应该返回并删除NIB的连接,但我已经删除了NIB文件!那么有什么建议吗?
//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;
}
修改
//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;
}
答案 0 :(得分:1)
你如何启动这个控制器?它是程序中唯一的控制器吗?如果是这样,请在Appdelegate didfinishloadingwithoptions上发布一些代码
*编辑
清理您的项目(xcode&gt;项目菜单&gt;清理)并重置您的模拟器&amp;看问题是否仍然存在。还要确保你的代码通过在那里放置一个断点来到达TableViewController中的initWithStyle方法。