gpt4 book ai didi

ios - 应用程序试图在目标上推送一个 nil View Controller

转载 作者:行者123 更新时间:2023-11-28 19:59:08 24 4
gpt4 key购买 nike

我正在创建一个没有 Storyboard的应用程序,当用户单击表格 View 单元格时,我无法从该单元格的详细 View 移动。

在我创建和处理 TableView 的类中,我有以下代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PersonDetailViewController *detailViewController;
Person *person = [self.playerArray objectAtIndex:indexPath.row];
detailViewController.person = person;
[[self navigationController] pushViewController:detailViewController animated:YES];

}

所以我试图将详细信息 View Controller 推送到屏幕上,然后在该详细信息屏幕上显示用户信息。我试图找到解决方案,但我遇到的大多数答案都使用 Storyboard,而我没有使用 Storyboard。

在我的 PersonDetailViewController.m 类中,我有以下代码:

#import "PersonDetailViewController.h"

@interface PersonDetailViewController ()

@end

@implementation PersonDetailViewController

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

- (void)viewDidLoad
{
[super viewDidLoad];
self.personInfo = [[UITextField alloc] initWithFrame:CGRectMake(45, 30, 200, 40)];
_personInfo.backgroundColor = [UIColor whiteColor];


}

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

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

我不确定这是否是问题的原因,但在我的代表中我有以下内容:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.tableViewController = [[TableViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.tableViewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}

我当时在想,这可能与创建导航 Controller 有关,但我一直在研究它,但我认为这与创建导航 Controller 无关。

最佳答案

您错过了 tableView:didSelectRowAtIndexPath: 方法中 View Controller 的初始化

PersonDetailViewController *detailViewController = [[PersonDetailViewController alloc] init]; // or initWith...

关于ios - 应用程序试图在目标上推送一个 nil View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24940335/

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