Search code examples
iosuitableviewpeek3dtouch

Peek in iOS 9 App Crashing


I am trying to do Peek and Pop in my iOS 9 capable app. The view in question has a UITableView, so I have in my code:

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {

    // check if we're not already displaying a preview controller
    if ([self.presentedViewController isKindOfClass:[WebViewController class]]) {
        return nil;
    }

    // shallow press: return the preview controller here (peek)
        self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];




    return self.webViewController;
}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {

    // deep press: bring up the commit view controller (pop)
    self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];


    [self showViewController:self.webViewController sender:self];
}

WebViewController is the ViewController I have already set up to display the content when the row of the tableview is selected. The error I get is:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'
*** First throw call stack:
(0x182160f5c 0x19764bf80 0x182160ea4 0x182fb8868 0x1001307a4 0x1876cf9ac 0x1876cf720 0x187a025f8 0x187960844 0x18796cde4 0x1876a91e4 0x182117c30 0x1821159d4 0x182115e04 0x182044dc0 0x18d4e0088 0x18771ef60 0x10014ca68 0x197e6a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

Solution

  • Your log it's saying exactly what is wrong with your code:

    -[__NSCFConstantString stringByAppendingString:]: nil argument'

    You are performing stringByAppendingString passing a value that is nil

    Also, autorelease is not used anymore if you are using ARC (it's default by now)