首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITabBarItem动作给NSException

UITabBarItem动作给NSException
EN

Stack Overflow用户
提问于 2017-03-03 13:03:35
回答 1查看 621关注 0票数 0

我有一个4 UITabBarItems的自定义UITabBarItems,如下所示。

下面是我代码的相关部分:

代码语言:javascript
复制
class BaseItemViewController: UIViewController,UITabBarDelegate{

@IBOutlet var customTabBar: UITabBar!

在viewDidLoad中:

代码语言:javascript
复制
self.customTabBar.delegate = self

自定义功能:

代码语言:javascript
复制
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文件中的下面一行出现了错误。

代码语言:javascript
复制
class AppDelegate: UIResponder, UIApplicationDelegate {

线程1:信号SIGABRT

此外,控制台还打印以下内容:

177-03-03 18:25:41.318 xxxxx1667:706023 *终止应用程序由于未察觉的异常'NSUnknownKeyException',原因:‘setValue:forUndefinedKey::该类不符合键NearbyHotelsButton的键值编码。’*第一次抛出调用堆栈:(0 CoreFoundation 0x010f8494 exceptionPreprocess + 180 1 libobjc.A.dylib ) 0x00bb9e02 objc_exception_throw + 50 2 CoreFoundation 0x010f80b1 -NSException 17 +17 3 Foundation 0x0084b7f8 -NSObject(NSKeyValueCoding) setValue:forUndefinedKey:+ 282 4 Foundation 0x007a5e6a _NSSetUsingKeyValueSetter + 115 5 Foundation 0x007a5def -NSObject(NSKeyValueCoding) setValue:forKey:+ 295 6 UIKit 0x01d1c931 -UIViewController setValue:forKey:+857 Foundation 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实例化0x01f980fc:options:+ 2102 12 UIKit 0x01d24380 -UIViewController _loadViewFromNibNamed:bundle:+ 429 13 UIKit 0x01d24db8 -UIViewController loadView + 189 14 UIKit 0x01d251c4 -UIViewController loadViewIfRequired + 154 15 UIKit 0x01d2bcca -UIViewController __viewWillAppear:+ 114 16 UIKit -UIViewController(UIContainerViewControllerProtectedMethods) 0x01d4ee45开始外观转换:动画:+ 202 17 UIKit 0x01d61258 -UINavigationController _startCustomTransition:+ 1389 18 UIKit 0x01d7302 d -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表演者:withObject:+ 70 23 QuartzCore 0x07ac7096 -CALayer layoutSublayers + 144 24 QuartzCore _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 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 31 CoreFoundation 0x0100a6be __CFRunLoopDoObservers + 398 32 CoreFoundation 0x0100003c __CFRunLoopRun + 1340 33 CoreFoundation 0x00fff 846 CFRunLoopRunSpecific + 470 34 CoreFoundation 0x00fff65b CFRunLoopRunInMode + 123 35 GraphicsServices 0x04308664 GSEventRunModal + 192 36 GraphicsServices 0x043084a1 GSEventRun +10437 UIKit 0x01b54eb9 UIApplicationMain +16038 Voyate 0x000d6681 main + 145 39 libdyld.dylib 0x04b20a25启动+1 40? 0x000001 0x0 +1 libc++abi.dylib:以NSException (lldb)类型的完全例外终止

我在this question中使用了类似的例子进行了尝试。为什么会出现这个错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-03 13:07:26

这不是问题行动。这是从故事板加载视图控制器的问题。您有名为NearbyHotelsButton.的IBOutlet但是您的视图控制器没有此属性。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42579635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档