//My VIEwController.h@interface MyVIEwController: UIVIEwController<UIGestureRecognizerDelegate>/* ... */@property (nonatomic,retain) IBOutlet UIToolbar *toolbar;@property (nonatomic,retain) IBOutlet UILongPressGestureRecognizer *longPressGesureRecognizer;/* ... */- (IBAction)handleGesture;@end
以下代码然后工作:
- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; //configure UILongPressGestureRecognizer if(self.longPressGesureRecognizer == nil){ UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture)]; longPress.minimumPressDuration = 1.5; longPress.numberOftouchesrequired = 1; longPress.delegate = self; self.longPressGesureRecognizer = longPress; [self.toolbar addGestureRecognizer:self.longPressGesureRecognizer]; [longPress release]; } }- (BOol)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceivetouch:(UItouch *)touch{ return YES;}- (IBAction)handleGesture{ NSLog(@"Got a gesture!");}
我认为我的VIEw Controller中不需要UILongPressGestureRecognizer.当我尝试在MyVIEwController.xib文件中完全创建它时,我使用XCode 4.2执行了以下 *** 作
>在我的UIToolbar中在xib上附加了一个UILongPressRecognizer(附加到MyVIEwController中的toolbar).
>将UILongPressRecognizer的委托属性设置为文件所有者
>将selector属性设置为MyVIEwController的handleGesture消息.
当我在模拟器中运行应用程序时,我崩溃了控制台中的以下gdb错误:
*** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '-[UILongPressGestureRecognizer initWithCoder:]: unrecognized selector sent to instance
很明显UILongPressGestureRecognizer initWithCoder:没有实施,但我想知道在xib文件中设置UIGestureRecognizer的正确方法是什么. XCode在那里有手势,我已将它连接到一个视图.我不明白我的错.我在UIGestureRecognizer上看到的所有链接,包括Apple的UIGestureRecognizer’s class reference,总是使用代码中的UIGestureRecognizer.我没有看到仅使用xib文件来配置它的示例.
我不太关心这个问题,因为我可以使用VIEwController中的代码处理它,但我很困惑,如果UILongPressGestureRecognizer和/或UIGestureRecognizer不符合NSCoding协议,为什么XCode允许在nib中添加手势识别器和initWithCoder将被调用.我的直觉说问题出在我的最后,而不是Apple,但我很想知道出了什么问题.
谢谢!
更新
我似乎只在使用UISplitVIEwController时在测试中看到这种行为.如果我创建一个基于VIEwController的项目,UIGestureRecognizer将按预期工作.如果我在UISplitVIEwController应用程序的DetailVIEw上添加一个手势识别器,我会发生这样的崩溃:
2011-11-03 10:17:55.873 GestureSplitVIEwTest[1143:b603] -[UILongPressGestureRecognizer initWithCoder:]: unrecognized selector sent to instance 0x59696b02011-11-03 10:17:55.877 GestureSplitVIEwTest[1143:b603] *** Terminating app due to uncaught exception 'NSinvalidargumentexception',reason: '-[UILongPressGestureRecognizer initWithCoder:]: unrecognized selector sent to instance 0x59696b0'*** Call stack at first throw:( 0 CoreFoundation 0x011b15a9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x01305313 objc_exception_throw + 44 2 CoreFoundation 0x011b30bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x01122966 ___forwarding___ + 966 4 CoreFoundation 0x01122522 _CF_forwarding_prep_0 + 50 5 UIKit 0x002fe9fd UINibDecoderDecodeObjectForValue + 2592 6 UIKit 0x002fe2f5 UINibDecoderDecodeObjectForValue + 792 7 UIKit 0x002ff6ac -[UINibDecoder decodeObjectForKey:] + 398 8 UIKit 0x00214979 -[UIRuntimeConnection initWithCoder:] + 212 9 UIKit 0x003d34a8 -[UIRuntimeOutletCollectionConnection initWithCoder:] + 64 10 UIKit 0x002fe9fd UINibDecoderDecodeObjectForValue + 2592 11 UIKit 0x002fe2f5 UINibDecoderDecodeObjectForValue + 792 12 UIKit 0x002ff6ac -[UINibDecoder decodeObjectForKey:] + 398 13 UIKit 0x00213c36 -[UINib instantiateWithOwner:options:] + 804 14 UIKit 0x00215ab7 -[NSBundle(UINSBundleAdditions) loadNibnamed:owner:options:] + 168 15 UIKit 0x000cb628 -[UIVIEwController _loadVIEwFromNibnamed:bundle:] + 70 16 UIKit 0x000c9134 -[UIVIEwController loadVIEw] + 120 17 UIKit 0x000c900e -[UIVIEwController vIEw] + 56 18 UIKit 0x000c7482 -[UIVIEwController contentScrollVIEw] + 42 19 UIKit 0x000d7f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForVIEwController:] + 48 20 UIKit 0x000d6555 -[UINavigationController _layoutVIEwController:] + 43 21 UIKit 0x000d7870 -[UINavigationController _startTransition:fromVIEwController:toVIEwController:] + 524 22 UIKit 0x000d232a -[UINavigationController _startDeferredTransitionIfNeeded] + 266 23 UIKit 0x001ed2e9 -[UILayoutContainerVIEw layoutSubvIEws] + 226 24 QuartzCore 0x01888a5a -[CALayer layoutSublayers] + 181 25 QuartzCore 0x0188addc CALayerLayoutIfNeeded + 220 26 QuartzCore 0x018300b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 27 QuartzCore 0x01831294 _ZN2CA11Transaction6commitEv + 292 28 UIKit 0x0001b9c9 -[UIApplication _reportAppLaunchFinished] + 39 29 UIKit 0x0001be83 -[UIApplication _runWithURL:payload:launchOrIEntation:statusbarStyle:statusbarHIDden:] + 690 30 UIKit 0x00026617 -[UIApplication handleEvent:withNewEvent:] + 1533 31 UIKit 0x0001eabf -[UIApplication sendEvent:] + 71 32 UIKit 0x00023f2e _UIApplicationHandleEvent + 7576 33 GraphiCSServices 0x00eb2992 PurpleEventCallback + 1550 34 CoreFoundation 0x01192944 __CFRUNLOOP_IS_CALliNG_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 35 CoreFoundation 0x010f2cf7 __CFRunLoopDoSource1 + 215 36 CoreFoundation 0x010eff83 __CFRunLoopRun + 979 37 CoreFoundation 0x010ef840 CFRunLoopRunspecific + 208 38 CoreFoundation 0x010ef761 CFRunLoopRunInMode + 97 39 UIKit 0x0001b7d2 -[UIApplication _run] + 623 40 UIKit 0x00027c93 UIApplicationMain + 1160 41 GestureSplitVIEwTest 0x0000234a main + 170 42 GestureSplitVIEwTest 0x00002295 start + 53)terminate called throwing an exceptionsharedlibrary apply-load-rules allCurrent language: auto; currently objective-c(gdb)解决方法 您确定没有使用iOS 4.3 SDK而不是iOS 5 SDK吗?
我花了30分钟才发现我使用的是错误的SDK.
总结以上是内存溢出为你收集整理的ios – 为什么在nib中创建UIGestureRecognizer子类会导致使用UISplitViewController崩溃全部内容,希望文章能够帮你解决ios – 为什么在nib中创建UIGestureRecognizer子类会导致使用UISplitViewController崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)