2017-03-03 60 views
0

我有一个自定义的UITabBar与4 UITabBarItems如下所示。UITabBarItem action给NSException

enter image description here

enter image description here

这里是我的代码的相关部分:

class BaseItemViewController: UIViewController,UITabBarDelegate{ 

@IBOutlet var customTabBar: UITabBar! 
在viewDidLoad中

self.customTabBar.delegate = self 

自定义函数:

func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) { 
     if item.tag == 0 { 
      print("Tag one") 
     } else if item.tag == 1 { 
      print("Tag two") 
     } else if item.tag == 2 { 
      print("Tag three") 
     } else if item.tag == 3 { 
      print("Tag four") 
     } 
    } 

我需要做一个动作,一旦我点击标签栏项目。我已经向UIBarButtonItems添加了标签,但是当我运行该应用程序时,appDelegate文件中的以下行中出现错误。

class AppDelegate: UIResponder, UIApplicationDelegate { 

线程1:信号SIGABRT

另外控制台打印以下:

2017年3月3日18:25:41.318 XXXXXX [ 1667:706023] *终止应用程序由于 未捕获异常'NSUnknownKeyExceptio n',原因: '[ setValue:forUndefinedKey:]:此类不是关键值 编码符合关键的NearbyHotelsButton。' *第一掷调用堆栈:(0的CoreFoundation 0x010f8494 exceptionPreprocess + 180 1 libobjc.A.dylib
0x00bb9e02 objc_exception_throw + 50 2的CoreFoundation
0x010f80b1 - [NSException提高] + 17 3基础
0x0084b7f8 - [NSObject的(的NSKeyValueCoding )的setValue:forUndefinedKey:] + 282 4基金会0x007a5e6a _NSSetUsingKeyValueSetter + 115 5基金会0x007a5def - [NSObject的(的NSKeyValueCoding)的setValue:forKey:] + 295 6
的UIKit 0x01d1c931 - [UIViewController中 的setValue:forKey:] + 85 7基金会
0x007da54b - [NSObject(NSKeyValueCoding)setValue:forKeyPath:] + 384 8 UIKit 0x01f99a62 - [UIRuntimeOutletConnection connect] + 132 9 libobjc.A。dylib 0x00bce00c - [NSObject的performSelector:] + 62 10的CoreFoundation
0x01021131 - [NSArray的makeObjectsPerformSelector:] + 273 11的UIKit
0x01f980fc - [UINib instantiateWithOwner:选择:] + 2102 12的UIKit
0x01d24380 - [UIViewController中_loadViewFromNibNamed:束: ] + 429 13 的UIKit 0x01d24db8 - [UIViewController中 的loadView] + 189 14的UIKit 0x01d251c4 - [UIViewController中loadViewIfRequired] + 154 15的UIKit 0x01d2bcca - [UIViewController中__viewWillAppear:] + 114 16的UIKit
0x01d4ee45 - [UIViewController中(UIContainerViewControllerProtectedMethods)beginAppearanceTransition :动画:] + 202 17 UIKit
0x01d61258 - [UINavigationController的_startCustomTransition:] + 1389 18的UIKit 0x01d7302d - [UINavigationController的_startDeferredTransitionIfNeeded:] + 803 19的UIKit 0x01d7439e - [UINavigationController的__viewWillLayoutSubviews] + 68 20的UIKit 0x01f594b7 - [UILayoutContainerView layoutSubviews] + 252 21的UIKit
0x01c253d4 - [UIView的(CALayerDelegate)layoutSublayersOfLayer:] + 810 22 libobjc.A.dylib 0x00bce059 - [NSObject的 performSelector:withObject:] + 70 23 QuartzCore
0x07ac7096 - [CALayer的layoutSublayers] + 144 24 QuartzCore
0x07aba8b6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388 25 QuartzCore 0x07aba71a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 26 QuartzCore 0x07aacee7 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317 27 QuartzCore 0x07ae1847 _ZN2CA11Transaction6commitEv + 561 28 QuartzCore 0x07ae30b8 _ZN2CA11Transaction17flush_transactionEv + 50 29的UIKit
0x01b86f55 _afterCACommitHandler + 197 30的CoreFoundation
0x0100a75e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 30 31的CoreFoundation 0x0100a6be __CFRunLoopDoObservers + 398 32 CoreFoundation 0x0100003c __CFRunLoopRun + 1340 33 CoreFoundation 0x00fff846 CFRunLoopRunSpecific + 470 34的CoreFoundation
0x00fff65b CFRunLoopRunInMode + 123个35 GraphicsServices
0x04308664 GSEventRunModal + 192个36 GraphicsServices
0x043084a1 GSEventRun + 104 37的UIKit
0x01b54eb9 UIApplicationMain + 160 38 Voyate
0x000d6681主+ 145 39 libdyld.dylib
0x04b20a25开始+ 1 40
00000001为0x0 + 1)的libC++ abi.dylib:与未捕获 异常类型NSException(LLDB的)

终止我试图此使用this question一个类似的例子。为什么会出现这个错误?

+1

问题不在这里,问题是在你的按钮检查此按钮'NearbyHotelsButton'是否使用' –

+1

看到这个http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception- reason-this-class-is-not-key-v –

回答

1

这不是问题的措施。这是从故事板加载视图控制器的问题。您已有IBOutlet名称Nearby HotelsButton。但你viewcontroller没有这个属性。

+0

删除了引用出口到'NearbyHotelsButton',这是残留物。它的工作。谢谢! –