objective-c - UISplitViewController EXC_BAD_ACCESS 使用 ARC 旋转

标签 objective-c ios uiviewcontroller uisplitviewcontroller

我在 ARC 上使用 UISplitViewController 但它似乎在几次旋转事件后崩溃了:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x80069f69
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x32461f78 objc_msgSend + 16
1   UIKit                           0x3588b280 -[UISplitViewController _calculateDelegateHiddenMasterOrientations] + 52
2   UIKit                           0x3588cca8 -[UISplitViewController setViewControllers:] + 1344
3   PUC                             0x000d0a42 0x1000 + 850498
4   UIKit                           0x35644ade -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 938
5   UIKit                           0x356be7a4 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 152

此外,当我启动应用程序时,出现此错误:

Splitview controller <PUCSplitViewController: 0x36c290> is expected to have a master view controller before its used!

我错过了什么?我将其设置为与 Apple 提供的示例项目非常相似。

切换详细 View 时有时也会崩溃:

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

    // Clicked Asset
    Asset *asset = [items objectAtIndex:indexPath.row];

    UIViewController *detailViewController = nil;

    // See what asset we are on
    if ([asset.title isEqualToString:@"News"]) {
        News2 *news = [[News2 alloc] initWithStyle:UITableViewStyleGrouped];
        UINavigationController *newsNav = [[UINavigationController alloc] initWithRootViewController:news];
        detailViewController = newsNav;
    } else if ([asset.title isEqualToString:@"Photos"]) {
        PhotosiPad *photos = [[PhotosiPad alloc] init];
        UINavigationController *photosNav = [[UINavigationController alloc] initWithRootViewController:photos];
        detailViewController = photosNav;
    }

    // Update the split view
    [PUCAppDelegate instance].mainSplitViewController.viewControllers = [NSArray arrayWithObjects:self.navigationController, detailViewController, nil];

    // Dismiss the popover if it's present.
    if (popoverController != nil) {
        [popoverController dismissPopoverAnimated:YES];
    }

}//end

下面是我如何在 applicationDidFinishLoading 中创建 UISplitViewController:

PUCSplitViewController *splitPUC = [[PUCSplitViewController alloc] init];
self.mainSplitViewController = splitPUC;
[self.window addSubview:self.mainSplitViewController.view];
[self.window makeKeyAndVisible];

想法?

最佳答案

对于

is expected to have a master view controller before its used!

错误,

您需要在为 splitviewcontroller 设置 View Controller 之后设置委托(delegate)。

参见 Use Your Loaf blog from April 6th, 2012 (不,这不是我的)。

关于objective-c - UISplitViewController EXC_BAD_ACCESS 使用 ARC 旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9676776/

相关文章:

iphone - Accordion 表格单元格 - 如何动态扩展/收缩 uitableviewcell?

objective-c - 如何获得相对日期

ios - 如何使按钮在 UIScrollView 内滚动?

iPhone - 使用哪些 View Controller 方法

ios - 如何使用 UIScrollView 实现 UIPageViewController?

ios - 简单的录音应用程序 "uncaught NSException"

swift - 何时使用 View 而不是 ViewController

ios - 在 iOS 9 中,为什么 SFSafariViewController 被推送而不是模态呈现?

ios - NSTimer 不调用方法

ios - 旋转后改变棋盘颜色