1
當我更改詳細視圖時,我的iPad應用程序崩潰。我設置了一個異常斷點來查明導致問題的代碼行。它似乎發生得相當零星,所以我不確定發生了什麼事情。有什麼建議麼?在我的主視圖控制器EXC_BAD_ACCESS(code = 1)錯誤的主從應用程序
self.splitViewController.viewControllers = details;
我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;
}
這也是另一種觀點認爲在這裏做的:
例如,墜毀在這一行
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]);
}
編輯:應用程序似乎當我在主視圖控制器表視圖選擇第一行,以顯示初始細節視圖然後選擇另一行顯示不同的內容崩潰。如果我不在任何時候選擇第一行,一切正常。
爲什麼要將窗口的根視圖控制器設置爲分割視圖控制器?它不是已經是根視圖控制器嗎? – rdelmar
您可能會發現這有助於調試EXC_BAD_ACCESS錯誤,因爲我有時會這樣做。它的要點是在調試器中使用'register read'命令並查看寄存器以確定崩潰之前調用的最後一個函數。從中你可以確定你正在嘗試使用該功能的對象。而且一旦你知道哪個交易對象正在被訪問,你可以想出如何安全地調用它或者以某種方式保留它。 http://sealiesoftware.com/blog/archive/2008/09/22/objc_explain_So_you_crashed_in_objc_msgSend.html – jmathew
你可能還需要這個http://lldb.llvm.org/lldb-gdb.html我發佈的鏈接。 – jmathew