gpt4 book ai didi

ios - 主从应用程序中的 EXC_BAD_ACCESS(code=1) 错误

转载 作者:行者123 更新时间:2023-11-29 13:08:12 24 4
gpt4 key购买 nike

当我更改详细 View 时,我的 iPad 应用程序崩溃了。我设置了一个异常断点来查明导致问题的代码行。它似乎偶尔会发生,所以我不太确定发生了什么。有什么建议吗?

例如,它在这一行崩溃了:

self.splitViewController.viewControllers = details;

在我的主视图 Controller 中的 didSelectRowAtIndexPath 方法中

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
KFBDetailViewController *detailViewController = [[KFBDetailViewController alloc] initWithNibName:@"KFBDetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];

[details replaceObjectAtIndex:1 withObject:detailNavigationController];

self.splitViewController.viewControllers = details;

KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.window.rootViewController = self.splitViewController;
}

它在另一个 View 中也是这样做的:

appDelegate.splitViewController.viewControllers = details;

这是那个的 didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];

UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:webViewController];

[details replaceObjectAtIndex:1 withObject:detailNav];

KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];

appDelegate.splitViewController.viewControllers = details;
appDelegate.window.rootViewController = self.splitViewController;
appDelegate.splitViewController.delegate = webViewController;

[appDelegate.splitViewController viewWillAppear:YES];

// Grab the selected item
RSSItem *entry = [[channel items]objectAtIndex:[indexPath row]];

NSLog(@"Channel Items: %@", [[channel items]objectAtIndex:[indexPath row]]);

// Construct a URL with the link string of the item
NSURL *url = [NSURL URLWithString:[entry link]];

NSLog(@"Link: %@", [entry link]);

// Construct a request object with that URL
NSURLRequest *req = [NSURLRequest requestWithURL:url];

NSLog(@"URL: %@", url);

// Load the request into the web view
[[webViewController webView]loadRequest:req];
webViewController.hackyURL = url;
NSLog(@"Request: %@", req);

// Set the title of the web view controller's navigation item
[[webViewController navigationItem]setTitle:[entry title]];

NSLog(@"Title: %@", [entry title]);
}

编辑:当我选择主视图 Controller TableView 中的第一行以显示初始详细信息 View 然后选择另一行以显示不同内容时,应用似乎崩溃了。如果我在任何时候都不选择第一行,一切正常。

最佳答案

我设法通过调整在主视图中点击第一行时显示初始详细 View 的方式来解决问题。

您可以在我的原始帖子中看到原始实现。以下是我的更改方式。

if (indexPath.row == 0)
{
KFBDetailViewController *detailViewController = [[KFBDetailViewController alloc]initWithNibName:@"KFBDetailViewController_iPad" bundle:nil];

NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];

UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:detailViewController];

[details replaceObjectAtIndex:1 withObject:detailNav];

KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.splitViewController.viewControllers = details;
appDelegate.window.rootViewController = self.splitViewController;
appDelegate.splitViewController.delegate = detailViewController;
[appDelegate.splitViewController viewWillAppear:YES];
}

关于ios - 主从应用程序中的 EXC_BAD_ACCESS(code=1) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18067079/

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