gpt4 book ai didi

ios - 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因 : 'Could not load NIB in bundle:

转载 作者:可可西里 更新时间:2023-11-01 05:23:18 24 4
gpt4 key购买 nike

我有两个 View Controller ,GroupListViewController 和 GroupDetailViewController,来回切换,当通过单击行单元格来回切换时,运行出错,我什至没有xib。我以编程方式完成所有组件。在这里搜索相同的问题,这不是我的类型。

在下面的代码片段中,“CustomGroupListViewCell *plcc” CustomGroupListViewCell 是一个自定义的 UITableViewCell,你可以实现一个空的转储,

在此处列出代码。

GroupListViewController.h

#import <UIKit/UIKit.h>


@class GroupDetailViewController;

@interface GroupListViewController : UITableViewController
{
NSArray * contentArray;
GroupDetailViewController * dvController;
}

@property (nonatomic, retain) GroupDetailViewController * dvController;

@end

GroupListViewController.m

#import "GroupListViewController.h"
#import "CustomGroupListViewCell.h"
#import "ZYAppDelegate.h"
#import "GroupDetailViewController.h"

@interface GroupListViewController ()
@end

@implementation GroupListViewController

@synthesize dvController;

- (void) viewDidLoad
{
contentArray = [[NSArray arrayWithObjects:@"heyun", @"wushi", @"ios", nil]retain];

[super viewDidLoad];

}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void) dealloc
{
[dvController release];
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear: animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear: animated];
}

- (void)viewDisDisappear:(BOOL)animated
{
[super viewDidDisappear: animated];
}

- (NSInteger)numberOfSectionsInTableView: (UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return [contentArray count];
}

// custom row height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// dynamic with whether the cell has the gourp image or not..
return 160;
}

// Customize the appearance of table view cells
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PartyListCustomCell";

CustomGroupListViewCell *plcc = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(plcc == nil)
{
plcc = [[[CustomGroupListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}


// set up custom cell
plcc.gourpTitle.text = @"gourpTitle";


return plcc;

}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

if (dvController == nil)
{
GroupDetailViewController *aController = [[GroupDetailViewController alloc] initWithNibName:@"GroupDetailViewController" bundle:nil];

self.dvController = aController;

[aController release];
}

[dvController updateRowNumber:indexPath.row];
[[self navigationController] pushViewController:dvController animated:YES];

}

@end

GroupDetailViewController.h

#import <UIKit/UIKit.h>

@interface GroupDetailViewController : UITableViewController
{
int rowNumber;
}

@property(readwrite) int rowNumber;
- (void) updateRowNumber:(int) theindex;

@end

GroupDetailViewController.m

#import "GroupDetailViewController.h"

@interface GroupDetailViewController ()

@end

@implementation GroupDetailViewController

@synthesize rowNumber;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}

- (void) updateRowNumber: (int) theindex
{

rowNumber = theindex + 1;

UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];

label1.text = [NSString stringWithFormat:@"row %i was clicked ", rowNumber];
[self.view addSubview: label1];
[label1 release];

}

- (void)dealloc
{

[super dealloc];
}

- (void)viewDidLoad
{

UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];

label1.text = [NSString stringWithFormat:@"row %i was clicked ", rowNumber];

[self.view addSubview: label1];


[super viewDidLoad];
[label1 release];
// Do any additional setup after loading the view from its nib.
}

- (void)fetchedData: (NSData *)responseData
{
// parse out the json data
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Do any additional setup after loading the view from its nib.
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear: animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

最佳答案

通过调用初始化 View Controller 时

[[GroupDetailViewController alloc] initWithNibName:@"GroupDetailViewController" bundle:nil];

我们期待您提供相应的 xib(“GroupDetailViewController”)。如果您不想使用 xib,只需调用

[[GroupDetailViewController alloc] init]

并在您的 GroupDetailViewController 类中实现 loadView

关于ios - 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因 : 'Could not load NIB in bundle:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13362913/

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