gpt4 book ai didi

ios - 错误 : UITableViewController loaded the "TableViewController" nib but didn't get a UITableView HOWEVER I've already deleted the NIB file

转载 作者:行者123 更新时间:2023-11-29 03:06:37 25 4
gpt4 key购买 nike

在我的应用程序中,我正在将 UITableView 从以编程方式添加更改为通过 XIB 添加。决定放弃这个想法并返回,但现在应用程序崩溃了

message:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "TableViewController" nib but didn't get a 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;
}

最佳答案

你如何初始化这个 Controller ?它是程序中唯一的 Controller 吗?如果是这样,请在 Appdelegate didfinishloadingwithoptions 上发布一些代码

*编辑

清理你的项目(xcode > project menu > clean)并重置你的模拟器,看看问题是否仍然存在。还要通过在此处放置断点来确保您的代码到达 TableViewController 中的 initWithStyle 方法。

关于ios - 错误 : UITableViewController loaded the "TableViewController" nib but didn't get a UITableView HOWEVER I've already deleted the NIB file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22703025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com