2017-03-03 1 views
0

다음과 같이 4 개의 UITabBarItems가있는 사용자 정의 UITabBar가 있습니다. 있는 viewDidLoad에서NSIT를 제공하는 UITabBarItem 액션

class BaseItemViewController: UIViewController,UITabBarDelegate{ 

@IBOutlet var customTabBar: UITabBar! 

:

self.customTabBar.delegate = self 

사용자 정의 기능 :

여기

enter image description here

enter image description here

내 코드의 관련 부분입니다
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에 태그를 추가했지만 app을 실행할 때 appDelegate 파일의 다음 줄에 오류가 있습니다.

스레드 1 말

class AppDelegate: UIResponder, UIApplicationDelegate { 

:

2017년 3월 3일 18 : 25 : 41.318 XXXXXX [SIGABRT 신호를 또한 다음 콘솔 인쇄

1667 : 706023] * 캐치되지 않은 예외로 인해 앱 종료 중 'NSUnknownKeyExceptio n ', 이유 : '[ setValue : forUndefinedKey :] :이 클래스는 키 인접 값 버튼의 키 호환 값이 아닙니다. ' * 우선 투사 호출 스택 (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 : 선택해] + 2,102 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 : animated :] + 202 17 UIKit,960,453,210 0x01d61258는 - [UINavigationController가 _startCustomTransition는 :] - : + 803 19 UIKit 0x01d7439e - [UINavigationController가 __viewWillLayoutSubviews] + 68 20 UIKit의 0x01f594b7 - [UILayoutContainerView layoutSubviews] + 252 21 UIKit
0x01c253d4 [UINavigationController가 _startDeferredTransitionIfNeeded] + 1,389 18 UIKit은 을 0x01d7302d - [UIView의 (CALayerDelegate) layoutSublayersOfLayer :] + 810 22 libobjc.A.dylib 0x00bce059 - [NSObject의 performSelector : withObject :] + 70 23 QuartzCore
0x07ac7096 - [layoutSublayers의 CALayer] + 144 24 QuartzCore
0x07aba8b6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 26 QuartzCore 0x07aacee7 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317 27 QuartzCore 0x07ae1847 _ZN2CA11Transaction6commitEv + 561 388 25 QuartzCore의 0x07aba71a 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
GSEventRunModal 0x04308664 + 192 36 GraphicsServices
0x043084a1 GSEventRun + 104 37 UIKit
0x01b54eb9 UIApplicationMain + 160 38 Voyate
0x000d6681 메인 + 145 39 libdyld.dylib
0x04b20a25 시작 + 1 40 ???
0x00000001이 0x0 + 1)의 libC++ abi.dylib : 형식 NSException (lldb의 캐치되지 예외)

와 착신 I가 this question에서 동일한 예를 사용하여 이것을 시도. 이 오류가 왜 발생합니까?

+1

문제가 귀하의 버튼에 있습니다.이 버튼을 선택하십시오. NearbyHotelsButton'이 (가) 사용되었거나 사용되지 않았습니다. ' –

+1

참조하십시오. http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception- reason-this-class-is-not-key-v –

답변

1

이것은 문제의 행동이 아닙니다. 스토리 보드에서 viewcontroller를로드하는 중 문제가 발생했습니다. IBOutlet 이름이 인근 호텔 버튼입니다. 하지만 당신은 viewcontroller이 속성을 가지고 있지 않습니다.

+0

은 참조하는 콘센트를 잔여 물인'NearbyHotelsButton'으로 제거했습니다.그리고 효과가있었습니다. 감사! –