2017-01-06 23 views
2

我是編程的初學者,也是Stack Overflow的新手。我仍在搞清楚代碼和網站是如何工作的,所以如果我沒有正確使用它們,我很抱歉。 (我不是以英語爲母語的人,但我儘可能地盡我所能解釋我的問題)爲什麼「未知班」?

我正在使用Xcode Version 8.1和Swift。

我正在爲我的學校項目構建一個應用程序。我已經創建了待辦事項列表應用程序和倒數計時器應用程序。所以,我現在想把它們放在一個應用程序中。

我創建了一個新項目並插入了Tab Bar Controller。然後複製我在待辦事項列表和倒數計時器應用程序中使用的所有文件,並設置故事板。

沒有警告標記,但是當我運行模擬器時,出現錯誤,模擬器停止。我得到的錯誤是「主題1:信號SIGABRT」在此行中AppDelegate.swift:

class AppDelegate: UIResponder, UIApplicationDelegate { 

,並在控制檯消息:

2017-01-06 20:32:22.207 PP Final App[61701:3259153] Unknown class PomodoroViewController in Interface Builder file. 
2017-01-06 20:32:22.713 PP Final App[61701:3259153] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fd7faf075d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lbTimer.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x00000001100c234b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010fb2321e objc_exception_throw + 48 
    2 CoreFoundation      0x00000001100c2299 -[NSException raise] + 9 
    3 Foundation       0x000000010f63326f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291 
    4 UIKit        0x000000011067f4ef -[UIViewController setValue:forKey:] + 88 
    5 UIKit        0x00000001108f379e -[UIRuntimeOutletConnection connect] + 109 
    6 CoreFoundation      0x0000000110067590 -[NSArray makeObjectsPerformSelector:] + 256 
    7 UIKit        0x00000001108f2122 -[UINib instantiateWithOwner:options:] + 1867 
    8 UIKit        0x0000000110685c21 -[UIViewController _loadViewFromNibNamed:bundle:] + 386 
    9 UIKit        0x0000000110686543 -[UIViewController loadView] + 177 
    10 UIKit        0x0000000110686878 -[UIViewController loadViewIfRequired] + 201 
    11 UIKit        0x00000001106870cc -[UIViewController view] + 27 
    12 UIKit        0x00000001106e52df -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 483 
    13 UIKit        0x00000001106e4721 -[UITabBarController transitionFromViewController:toViewController:] + 59 
    14 UIKit        0x00000001106e05e2 -[UITabBarController _setSelectedViewController:] + 365 
    15 UIKit        0x00000001106e0464 -[UITabBarController setSelectedViewController:] + 234 
    16 UIKit        0x000000011059e6e6 +[UIView(Animation) performWithoutAnimation:] + 90 
    17 UIKit        0x00000001106daa00 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 354 
    18 UIKit        0x00000001106dbb7a -[UITabBarController viewWillAppear:] + 206 
    19 UIKit        0x000000011068ca0f -[UIViewController _setViewAppearState:isAnimating:] + 692 
    20 UIKit        0x000000011068d11f -[UIViewController __viewWillAppear:] + 147 
    21 UIKit        0x000000011068e913 -[UIViewController viewWillMoveToWindow:] + 507 
    22 UIKit        0x0000000110595151 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 621 
    23 UIKit        0x00000001105a5cf0 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 451 
    24 UIKit        0x00000001105947a1 -[UIView(Hierarchy) addSubview:] + 838 
    25 UIKit        0x0000000110550f5b -[UIWindow addRootViewControllerViewIfPossible] + 849 
    26 UIKit        0x00000001105513a2 -[UIWindow _setHidden:forced:] + 293 
    27 UIKit        0x0000000110564cb5 -[UIWindow makeKeyAndVisible] + 42 
    28 UIKit        0x00000001104ddc89 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818 
    29 UIKit        0x00000001104e3de9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731 
    30 UIKit        0x00000001104e0f69 -[UIApplication workspaceDidEndTransaction:] + 188 
    31 FrontBoardServices     0x0000000113ed3723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24 
    32 FrontBoardServices     0x0000000113ed359c -[FBSSerialQueue _performNext] + 189 
    33 FrontBoardServices     0x0000000113ed3925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 
    34 CoreFoundation      0x0000000110067311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    35 CoreFoundation      0x000000011004c59c __CFRunLoopDoSources0 + 556 
    36 CoreFoundation      0x000000011004ba86 __CFRunLoopRun + 918 
    37 CoreFoundation      0x000000011004b494 CFRunLoopRunSpecific + 420 
    38 UIKit        0x00000001104df7e6 -[UIApplication _run] + 434 
    39 UIKit        0x00000001104e5964 UIApplicationMain + 159 
    40 PP Final App      0x000000010f52c1cf main + 111 
    41 libdyld.dylib      0x000000011373c68d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

在這個消息,我看到「未知在Interface Builder文件中的類PomodoroViewController「。這是問題,對嗎?但我不知道爲什麼我收到這條消息。文件中有沒有問題?

是我使用Tab Bar Controller的方式嗎?

這裏的番茄視圖控制器的代碼文件:

PomodoroViewController

import UIKit 

class PomodoroViewController: UIViewController { 

    @IBOutlet weak var lbTimer: UILabel! 

    let pomodoroTime: TimeInterval = 60 * 25 //Pomodoro Timer 25 minutes 
    let formatter = DateFormatter() 
    var theTime: TimeInterval = 0.0 

    override func viewDidLoad(){ 
     super.viewDidLoad() 
     formatter.dateFormat = "mm:ss" 
     let startTime = Date(timeIntervalSinceReferenceDate: pomodoroTime) 
     lbTimer.text = formatter.string(from: startTime) 
    } 

    override func didReceiveMemoryWarning(){ 
     super.didReceiveMemoryWarning() 
    } 

    @IBAction func countDown(_ sender: UIButton) { 
     theTime = pomodoroTime 
     Timer.scheduledTimer(timeInterval: 1.0, 
          target: self, 
          selector: #selector(PomodoroViewController.tickTimer(timer:)), 
          userInfo: nil, 
          repeats: true) 
    } 

    func tickTimer(timer: Timer){ 
     theTime -= 1.0 
     let newTime = Date(timeIntervalSinceReferenceDate: theTime) 
     if theTime < 0.1 { 
      timer.invalidate() 
     } 
    } 

} 

,這是連環畫的樣子: storyboard

+0

你能在github上分享您的代碼審查? –

+5

視圖控制器的類是否在Interface Builder中設置爲「PomodoroViewController」? – vadian

+0

在自定義類字段下的故事板中,確保您的模塊指向您的應用程序。它應該讀取「當前」而不是「無」 – cjrieck

回答

0

這個錯誤是什麼意思是:

  1. 你有一個故事板(或者可能是一個xi b)表示其中一個視圖控制器是PomodoroViewController。但是...
  2. PomodoroViewController在應用程序運行時不存在。

消息說iOS試圖找到PomodoroViewController但它不在那裏,所以它試圖用UIViewController代替。除UIViewController不具有lbTimer屬性,這會導致應用程序崩潰。

有幾個原因,這可能發生:

  • 您可能忘記PomodoroViewController複製到新的項目。
  • 如果您確實複製了它,則可能未將其包含在應用目標中。 [Xcode項目中包含的文件可能不會被編譯,因爲您可能將同一個項目文件用於多個目標。]

在第二種情況下,確保該文件在文件檢查器檢查了Xcode的窗口的右側:

enter image description here

+0

我認爲問題將是模塊(目標)名稱中的空間。在問題中查看故事板的截圖,該項目被稱爲「PP Final App」。 – Sulthan