2017-10-21 83 views
0

我正在設計我的第一個應用程序,並且對Swift來說是相當新的。libC++ abi.dylib:以NSException類型的未捕獲異常終止 - 是否需要修復啓動屏幕或Viewcontroller?

我的應用程序將成功構建,但不會通過啓動屏幕並出現錯誤「libC++ abi.dylib:終止於類型爲NSException的未捕獲異常」。我在這發現的其他類似問題我試圖修復,但無法使其工作。

我不確定問題出在我的啓動屏幕上還是視圖控制器上。

還有一個關於「在Swift 4模式下使用Swift 3 @objc推斷已被棄用」的警告。

這是什麼原因導致的錯誤?

在此先感謝。

啓動屏幕代碼(應用程序代理):

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

var window: UIWindow? 


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Override point for customization after application launch. 
    return true 
} 

func applicationWillResignActive(_ application: UIApplication) { 
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 
} 

func applicationDidEnterBackground(_ application: UIApplication) { 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
} 

func applicationWillEnterForeground(_ application: UIApplication) { 
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
} 

func applicationDidBecomeActive(_ application: UIApplication) { 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
} 

func applicationWillTerminate(_ application: UIApplication) { 
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
} 


} 

視圖控制器代碼:

import UIKit 

class ViewController: UIViewController, UISearchBarDelegate { 

//connection that ties search bar in view to input for viewcontroller 

@IBOutlet weak var searchbar: UISearchBar! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    searchbar.delegate = self 
} 
//activates keyboard etc when searchbar clicked 
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { 
    searchBar.resignFirstResponder() 
    //(dncode) is string that will equal text as entered into search  bar 

    let dncode = String() 

    searchBar.text! = dncode 

    if let url = URL (string: "https://www.example.com/(dncode)") 
    { 


     //this section to check and auto open URL in default browser  "Safari" 
    if #available(iOS 10.0, *) 
    { 

     UIApplication.shared.open(url, options: [:], completionHandler: nil) 
    } else { 
     UIApplication.shared.openURL(url) 
    } 
} 
} 
} 

登錄:

Terminating app due to uncaught exception 'NSUnknownKeyException',  reason: '[<DNAppBeta.ViewController 0x7fe1edd095e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key SearchBar.' 
*** First throw call stack: 
(
0 CoreFoundation      0x000000010d5ad1cb __exceptionPreprocess + 171 

1 libobjc.A.dylib      0x0000000109189f41 objc_exception_throw + 48 

2 CoreFoundation      0x000000010d5ad119 -[NSException raise] + 9 

3 Foundation       0x0000000108bac1e3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292 

4 UIKit        0x000000010a17f41f -[UIViewController setValue:forKey:] + 87 

5 UIKit        0x000000010a46e9dd -[UIRuntimeOutletConnection connect] + 109 

6 CoreFoundation      0x000000010d55057d -[NSArray makeObjectsPerformSelector:] + 317 

7 UIKit        0x000000010a46d393 -[UINib instantiateWithOwner:options:] + 1856 

8 UIKit        0x000000010a1864e0 -[UIViewController _loadViewFromNibNamed:bundle:] + 383 

9 UIKit        0x000000010a186e0c -[UIViewController loadView] + 177 

10 UIKit        0x000000010a18713d -[UIViewController loadViewIfRequired] + 195 

11 UIKit        0x000000010a18799a -[UIViewController view] + 27 

12 UIKit        0x000000010a055ae3 -[UIWindow addRootViewControllerViewIfPossible] + 122 

13 UIKit        0x000000010a0561eb -[UIWindow _setHidden:forced:] + 294 

14 UIKit        0x000000010a069098 -[UIWindow makeKeyAndVisible] + 42 

15 UIKit        0x0000000109fdb521 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4711 

16 UIKit        0x0000000109fe0751 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720 

17 UIKit        0x000000010a3a5e00 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924 

18 UIKit        0x000000010a778840 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153 

19 UIKit        0x000000010a3a59f9 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249 

20 UIKit        0x000000010a3a6257 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 668 

21 UIKit        0x000000010ad19dd9 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262 

22 UIKit        0x000000010ad19c92 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444 

23 UIKit        0x000000010a9fb87e __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 420 

24 UIKit        0x000000010abf8e8e _performActionsWithDelayForTransitionContext + 100 

25 UIKit        0x000000010a9fb67a -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231 

26 UIKit        0x000000010a777e9d -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392 

27 UIKit        0x0000000109fdefd2 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523 

28 UIKit        0x000000010a5b389b -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369 

29 FrontBoardServices     0x00000001145761b4 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338 

30 FrontBoardServices     0x000000011457eca9 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235 

31 libdispatch.dylib     0x000000010e60243c _dispatch_client_callout + 8 
32 libdispatch.dylib     0x000000010e607af4 _dispatch_block_invoke_direct + 592 
33 FrontBoardServices     0x00000001145aa6ce __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24 
34 FrontBoardServices     0x00000001145aa384 -[FBSSerialQueue _performNext] + 464 
35 FrontBoardServices     0x00000001145aa8f3 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 
36 CoreFoundation      0x000000010d5502b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
37 CoreFoundation      0x000000010d5efd31 __CFRunLoopDoSource0 + 81 
38 CoreFoundation      0x000000010d534c19 __CFRunLoopDoSources0 + 185 
39 CoreFoundation      0x000000010d5341ff __CFRunLoopRun + 1279 
40 CoreFoundation      0x000000010d533a89 CFRunLoopRunSpecific + 409 
41 GraphicsServices     0x00000001116e79c6 GSEventRunModal + 62 
42 UIKit        0x0000000109fe223c UIApplicationMain + 159 
43 DoughNationAppBeta     0x000000010886a557 main + 55 
44 libdyld.dylib      0x000000010e67ed81 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
+0

您的代碼是好的,請檢查此:https://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key-v – Maor

回答

0

的問題是, @IBOutlet weak var searchbar: UISearchBar!@IBOutlet weak var SearchBar: UISearchBar!之前。 因此,當您在界面構建器中添加搜索欄的IBoutlet時,該屬性的名稱爲SearchBar。之後,您更改了代碼中的屬性名稱,現在您需要打開界面構建器並與iboutlet建立新的連接。這將解決您的問題。

+0

謝謝!你是對的,我有多個連接到搜索欄。一旦我把它們清理出來,就停止了崩潰。 – Daagoodr

相關問題