0

I've spent a few hours searching for a solution to this problem but I can't even seem to find anyone who's experienced it, let alone a solution.

In my project, I have a main view controller that pushes a second view controller containing a UIWebView. Both view controllers are embedded in a navigation controller. The push segue and WebView are both hooked up using IB.

The segue happens as expected and the web page loads and works fine until I try to type. Tapping on a text field brings up the keyboard, but the first key press crashes the app and gives the error:

-[NSNull length]: unrecognized selector sent to instance 0x1899068
2014-02-06 04:37:19.550 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1899068'
*** First throw call stack:
(
    0   CoreFoundation                      0x0174d5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014d08b6 objc_exception_throw + 44
...

This happens both in the Simulator and on device. I'm particularly confused because I'm not doing anything remotely complex. In the view controller that contains the WebView, I have the following viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [self.webView loadRequest:request];
}

and no other code. Google is used as an example site here, but it happens on every site I've tried. The weird thing is that if I remove the segue and present the Web View without the parent Navigation Controller, everything works fine, so it seems like the nav controller has something to do with it. As I said, the webView property is hooked up as an IB outlet. I've also tried adding it programatically, but the outcome was the same. As far as I can tell nothing in my first view controller should have any effect on this; like I said it's a Storyboard segue from a button. I can be sure sending length to NSNull is not anything I'm doing directly by myself, as I don't use the length selector anywhere in my code.

Any help would be greatly appreciated.

It was requested so the full error message is as follows:

-[NSNull length]: unrecognized selector sent to instance 0x1899068
2014-02-06 05:18:29.607 AppName[859:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1899068'
*** First throw call stack:
(
    0   CoreFoundation                      0x0174d5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014d08b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017ea903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0173d90b ___forwarding___ + 1019
    4   CoreFoundation                      0x0173d4ee _CF_forwarding_prep_0 + 14
    5   CoreFoundation                      0x016cd95c CFStringGetLength + 140
    6   CoreFoundation                      0x016e1284 CFStringCompareWithOptionsAndLocale + 52
    7   Foundation                          0x010db634 -[NSString compare:options:range:locale:] + 175
    8   Foundation                          0x010db580 -[NSString compare:options:range:] + 69
    9   Foundation                          0x010eda59 -[NSString caseInsensitiveCompare:] + 80
    10  UIKit                               0x00454f48 -[UIPhysicalKeyboardEvent _matchesKeyCommand:] + 280
    11  UIKit                               0x00398ac9 -[UIResponder(Internal) _keyCommandForEvent:] + 312
    12  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    13  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    14  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    15  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    16  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    17  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    18  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    19  UIKit                               0x00398b3b -[UIResponder(Internal) _keyCommandForEvent:] + 426
    20  UIKit                               0x00252176 -[UIApplication handleKeyHIDEvent:] + 226
    21  UIKit                               0x0023a07c _UIApplicationHandleEventQueue + 2954
    22  CoreFoundation                      0x016d683f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    23  CoreFoundation                      0x016d61cb __CFRunLoopDoSources0 + 235
    24  CoreFoundation                      0x016f329e __CFRunLoopRun + 910
    25  CoreFoundation                      0x016f2ac3 CFRunLoopRunSpecific + 467
    26  CoreFoundation                      0x016f28db CFRunLoopRunInMode + 123
    27  GraphicsServices                    0x036f29e2 GSEventRunModal + 192
    28  GraphicsServices                    0x036f2809 GSEventRun + 104
    29  UIKit                               0x0023ed3b UIApplicationMain + 1225
    30  AppName                             0x00003d3d main + 141
    31  libdyld.dylib                       0x01d8b70d start + 1
    32  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
deergomoo
  • 11
  • 3
  • did you try to add a break point for all the exceptions? and if still can't figure out, maybe paste all the codes around the stop point. That might be easier for us to help you. – Xu Yin Feb 06 '14 at 05:02
  • @XuYin I just tried that and I think the problem is coming from within a framework? All of the code displayed after breaking is a load of assembly. I'm definitely not sending length myself anywhere in my code. – deergomoo Feb 06 '14 at 05:13
  • Would you mind to paste the entire error message? – Xu Yin Feb 06 '14 at 05:15
  • @XuYin I added it to the bottom of my question – deergomoo Feb 06 '14 at 05:24
  • Hmm, i tried exactly same code,didn't crash for me. do you have anything else besides the webview? when you say type in a text field, is that another control you have on the view controller, or just the search box on google web page ? – Xu Yin Feb 06 '14 at 05:35
  • Just the webview, nothing else. And yeah I mean the Google search bar or any text field on a web page. – deergomoo Feb 06 '14 at 05:56
  • can you share your project, put on dropbox and share link. – Toseef Khilji Feb 06 '14 at 09:18
  • What line of code does it crash on? Have you add an exception breakpoint? – Popeye Feb 06 '14 at 09:55
  • @Popeye That's the thing, it doesn't crash on any of *my* code, the bottom of the stack trace is main.m then anything higher than that is assembly. The precise line it crashes on with the exception breakpoint is 0x23dd3b: xorl %eax, %eax – deergomoo Feb 06 '14 at 10:27
  • It's got to crash someone on your code otherwise it will be a huge error in Apples code and I very much don't think that is the case. Have you add an exception breakpoint in? Where does it crash when you add that in? – Popeye Feb 06 '14 at 10:32
  • I think I might have been misreading the list of threads as a stack trace, nevertheless the error does not seem to be originating from my code. I'll grab a screenshot of what happens when it crashes to clear things up. – deergomoo Feb 06 '14 at 10:35
  • http://i.imgur.com/rc2zDAa.png http://i.imgur.com/rK1tvVt.png Apologies if I'm missing something really obvious debugging wise. I'm still not very familiar with what Xcode has to offer for debugging. – deergomoo Feb 06 '14 at 10:43

2 Answers2

1

So I managed to fix this by not really doing anything. What eventually fixed it was deleting the Navigation Controller that all the VCs were embedded in, then embedding them back in a Nav Controller. Now it works completely. So I don't know if it was an errant setting or what.

deergomoo
  • 11
  • 3
  • I have a tabbarcontroller at the root and 3 navcontrollres with tableviewcontrollers in them. I removed the navcontroller from the first tableviewcontroller and re-added it and that didn't change anything. I added a new tableviewcontroller in a new navcontroller to the tabbarcontroller and still. It seems to be an issue of the storyboard file and not particular scenes or controllers. Any ideas are welcome. – marciokoko Oct 30 '14 at 15:23
0

@deergomoo sorry for my first answer. I wash it as false.

So, what do you think about next example? Is it similar to your project structure? I can't find crashes.

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UINavigationController *navController=[UINavigationController new];
    ViewController *viewController=[[ViewController alloc] init];
    [navController pushViewController:viewController animated:NO];
    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];

    return YES;
}

.

#import "ViewController.h"

@implementation ViewController

-  (void)viewDidLoad {
    [super viewDidLoad];

    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds
                                                          style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
                                                   reuseIdentifier:nil];
    cell.textLabel.text = @"Cell";
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"didSelectRowAtIndexPath");
    UIViewController *viewController = [UIViewController new];
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [viewController.view addSubview:webView];

    NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [webView loadRequest:request];

    [self.navigationController pushViewController:viewController animated:TRUE];
}

@end
Shklyar
  • 140
  • 1
  • 12
  • Unfortunately it's not an issue with the page not being loaded. Waiting until webViewDidFinishLoad: fires does not stop the crash. Conversely, presenting the Web View when it's not in a navigation controller does not crash even when the page has not finished loading. Thank you for your time though. – deergomoo Feb 06 '14 at 10:32