2014-02-06 42 views
0

我花了幾個小時尋找這個問題的解決方案,但我甚至無法找到任何經歷過它的人,更不用說解決方案了。導航控制器內的UIWebView在輸入時崩潰

在我的項目中,我有一個主視圖控制器,推動包含UIWebView的第二個視圖控制器。兩個視圖控制器都嵌入在導航控制器中。 push segue和WebView都使用IB連接起來。

segue按預期發生,網頁加載並正常工作,直到我嘗試鍵入。輕擊文本字段帶來了鍵盤,但第一次按鍵崩潰的應用程序,並給出了錯誤:

-[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 
... 

發生這種情況無論是在模擬器和設備。我特別困惑,因爲我沒有做任何複雜的事情。在包含WebView的視圖控制器中,我有以下viewDidLoad:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

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

    [self.webView loadRequest:request]; 
} 

並沒有其他代碼。 Google在這裏用作示例網站,但它發生在我嘗試過的每個網站上。奇怪的是,如果我刪除segue並在沒有父導航控制器的情況下呈現Web視圖,則一切正常,因此導航控制器似乎與它有關。正如我所說的,webView屬性作爲一個IB插座連接起來。我也試着以編程方式添加它,但結果是一樣的。據我所知,在我的第一個視圖中,控制器應該對此沒有任何影響;就像我說的那樣,它是一個按鈕上的Storyboard segue。我可以肯定,發送長度到NSNull不是我自己直接做的任何事情,因爲我沒有在我的代碼中的任何地方使用長度選擇器。

任何幫助將不勝感激。

會議要求,因此完整的錯誤信息如下:

-[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 
+0

您是否嘗試爲所有異常添加斷點?如果仍然無法弄清楚,可能會在停止點附近粘貼所有代碼。這對我們來說可能更容易幫助你。 –

+0

@XuYin我剛剛嘗試過,我認爲問題來自框架內?所有破解後顯示的代碼都是程序集的負載。我絕對不會在我的代碼中隨時隨地發送任何信息。 – deergomoo

+0

你介意粘貼整個錯誤信息嗎? –

回答

0

@deergomoo對不起我的第一個答案。我把它當作虛假的。

那麼,您如何看待下一個例子呢?它與您的項目結構相似嗎?我找不到崩潰。

@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 
+0

不幸的是,這不是沒有加載頁面的問題。等待直到webViewDidFinishLoad:觸發不會停止崩潰。相反,如果網頁視圖不在導航控制器中,即使頁面尚未完成加載,也不會崩潰。謝謝你的時間。 – deergomoo

1

所以我設法解決這個沒有做任何事情。最終解決的問題是刪除所有VC所嵌入的導航控制器,然後將其嵌入導航控制器中。現在它完全工作。所以我不知道這是一個錯誤的設置還是什麼。

+0

我有一個tabbarcontroller在根和3 navcontrollres與tableviewcontrollers在他們。我從第一個tableviewcontroller中刪除了navcontroller並重新添加了它,但這並沒有改變任何東西。我在一個新的navcontroller中添加了一個新的tableviewcontroller到tabbarcontroller,但仍然如此。這似乎是故事板文件的問題,而不是特定的場景或控制器。任何想法都歡迎。 – marciokoko

0

在我的情況下,我猜我的標籤欄控制器已經在我的故事板中變壞了。我不得不從它刪除所有視圖控制器插座。刪除標籤欄控制器。清理項目。添加一個新的標籤欄控制器並重新連線所有插座。然後我不再看到這次事故。

我只是提到它,所以它可能會幫助別人。

相關問題