2017-01-06 7 views
2

私はプログラミングの初心者であり、Stack Overflowについても新しいです。私はまだコードとこのウェブサイトの仕組みを理解しているので、正しく使用しなければ申し訳ありません。 (私はネイティブの英語のスピーカーではありませんが、私の質問については可能な限り説明しています)なぜ "不明なクラス"ですか?

私はXcodeバージョン8.1とSwiftを使用しています。

私は学校のプロジェクトのためのアプリを開発しています。私はすでにTo-Do-List AppとCountdown Timer Appを作成しました。だから、今私は一緒に1つのアプリに入れたいです。

私は新しいプロジェクトを作成し、Tab Bar Controllerを挿入しました。 To-Do-ListやCountdown Timerのアプリで使用したすべてのファイルをコピーし、ストーリーボードを設定します。

注意マークはありませんが、シミュレータを実行すると、エラーが表示され、シミュレータが停止します。 AppDelegate.swiftこの行で:私が得たエラーは、「シグナルSIGABRTスレッド1」:ある

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

View ControllerのクラスはInterface Builderで 'PomodoroViewController'に設定されていますか? – vadian

+0

カスタムクラスフィールドの下のストーリーボードで、モジュールがあなたのアプリを指していることを確認します。 "None"ではなく "Current"と表示されます。 – cjrieck

答えて

0

  1. あなたはストーリーボードを持っています(またはxi b)は、ビューコントローラの1つがPomodoroViewControllerであることを示します。しかし...
  2. PomodoroViewControllerは、アプリの実行中は存在しません。

メッセージは、iOSがPomodoroViewControllerを見つけることを試みたが、それはありませんでしたので、それは代わりにUIViewControllerを使用しようとしたと述べています。 UIViewControllerを除いて、lbTimerプロパティがないため、アプリがクラッシュします。

理由のカップルは、これが起こる可能性があります。

  • をあなたが新しいプロジェクトにPomodoroViewControllerをコピーすることを忘れているかもしれません。
  • コピーした場合は、アプリターゲットに含めないことがあります。 [複数のターゲットに対して同じプロジェクトファイルを使用する可能性があるため、コンパイルされないXcodeプロジェクトにファイルを含めることができます。]第2のケースで

を、ファイルがXcodeのウィンドウの右側にあるファイルインスペクタにチェックされていることを確認してください:

enter image description here

+0

私は問題がモジュール(ターゲット)名のスペースになると思います。質問でストーリーボードのスクリーンショットを参照してください、プロジェクトは 'PP最終アプリ'と呼ばれています。 – Sulthan

関連する問題