首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用UIPickerview作为UITextfield在iOS 8中的输入视图时崩溃

使用UIPickerview作为UITextfield在iOS 8中的输入视图时崩溃
EN

Stack Overflow用户
提问于 2014-11-13 01:08:21
回答 1查看 1.5K关注 0票数 0

我一直在使用UIPickerview作为UITextfield的输入,它非常适合于iOS 7,但是一旦我在iOS 8上运行它,每当我选择一个textfield输入数据时,它就会崩溃;我不知道为什么。

这是密码。

这在我的头文件中

代码语言:javascript
运行
复制
 @interface myViewController:UIViewController
 <UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>

 @property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
 @property (weak, nonatomic) IBOutlet UITextField *myTxtfield;

 @end

这是我的.m文件

代码语言:javascript
运行
复制
 @implementation myViewController

 - (void)viewDidLoad
 {
     [super viewDidLoad];

     NSString *filePath = [[NSBundle mainBundle]
     pathForResource:@"myData" ofType:@"plist"];

     data = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
     self.pickerView.showsSelectionIndicator = YES;
 }

 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
      return 1;
 }

 -(NSInteger)pickerView:(UIPickerView *)pickerView
 numberOfRowsInComponent:(NSInteger)component{
     return [data count];
 }

 -(NSString *)pickerView:(UIPickerView *)pickerView
  titleForRow:(NSInteger)row forComponent:(NSInteger)component{
      return [data objectAtIndex:row];
 }

 - (void)pickerView:(UIPickerView *)pickerView
 didSelectRow:(NSInteger)row inComponent:(NSInteger)component
 {
     currentTextField.text = [data objectAtIndex:row];
 }


 -(BOOL) textFieldShouldReturn:(UITextField *)textField{


     [_myTxtfield resignFirstResponder];

     return YES;
 }

 -(void)textFieldDidBeginEditing:(UITextField *)textField {

     if (_myTxtfield.isEditing==YES)
     {
         textField.inputView = _pickerView;
         currentTextField = textField;
      }

    [[textField valueForKey:@"textInputTraits"]
    setValue:[UIColor lightGrayColor] forKey:@"insertionPointColor"];
 }

 -(void)textFieldDidEndEditing:(UITextField *)textField {
             [_pickerView selectRow:0 inComponent:0 animated:NO];
 }

 @end

这是坠机信息

代码语言:javascript
运行
复制
 *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x7fa7fd412c40> should have parent view controller:<myViewController: 0x7fa7fb8b7600> but requested parent is:<UIInputWindowController: 0x7fa7fd87d600>'
 *** First throw call stack:
 (
     0   CoreFoundation                      0x0000000105521f35 __exceptionPreprocess + 165
     1   libobjc.A.dylib                     0x00000001051babb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000105521e6d +[NSException raise:format:] + 205
    3   UIKit                               0x000000010394889f -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 184
    4   UIKit                               0x0000000103ef5308 -[UIInputWindowController changeToInputViewSet:] + 491
    5   UIKit                               0x0000000103ef5ebd __43-[UIInputWindowController setInputViewSet:]_block_invoke + 85
     6   UIKit                               0x00000001038915ce +[UIView(Animation) performWithoutAnimation:] + 65
     7   UIKit                               0x0000000103ef5c8e -[UIInputWindowController setInputViewSet:] + 291
     8   UIKit                               0x0000000103ef1a7a -[UIInputWindowController performOperations:withAnimationStyle:] + 50
     9   UIKit                               0x0000000103ce1bce -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1054
     10  UIKit                               0x000000010399731d -[UIResponder becomeFirstResponder] + 468
     11  UIKit                               0x000000010388ce03 -[UIView(Hierarchy) becomeFirstResponder] + 99
     12  UIKit                               0x0000000103f53ad7 -[UITextField becomeFirstResponder] + 51
     13  UIKit                               0x0000000103bdb9c1 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 177
     14  UIKit                               0x0000000103bdda30 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2263
     15  UIKit                               0x0000000103bd32e6 _UIGestureRecognizerSendActions + 262
     16  UIKit                               0x0000000103bd1f89 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
     17  UIKit                               0x0000000103bd6ba6 ___UIGestureRecognizerUpdate_block_invoke662 + 51
     18  UIKit                               0x0000000103bd6aa2 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
     19  UIKit                               0x0000000103bccb1d _UIGestureRecognizerUpdate + 2796
     20  UIKit                               0x0000000103866ff6 -[UIWindow _sendGesturesForEvent:] + 1041
     21  UIKit                               0x0000000103867c23 -[UIWindow sendEvent:] + 667
     22  UIKit                               0x00000001038349b1 -[UIApplication sendEvent:] + 246
     23  UIKit                               0x0000000103841a7d _UIApplicationHandleEventFromQueueEvent + 17370
    24  UIKit                               0x000000010381d103 _UIApplicationHandleEventQueue + 1961
     25  CoreFoundation                      0x0000000105457551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
     26  CoreFoundation                      0x000000010544d41d __CFRunLoopDoSources0 + 269
     27  CoreFoundation                      0x000000010544ca54 __CFRunLoopRun + 868
    28  CoreFoundation                      0x000000010544c486 CFRunLoopRunSpecific + 470
    29  GraphicsServices                    0x00000001082cc9f0 GSEventRunModal + 161
    30  UIKit                               0x0000000103820420 UIApplicationMain + 1282
    31  أحسب نسبتك               0x0000000102a7afbd أحسب نسبتك + 8125
    32  libdyld.dylib                       0x0000000105f11145 start + 1
 )  

 libc++abi.dylib: terminating with uncaught exception of type NSException
EN

Stack Overflow用户

回答已采纳

发布于 2014-11-13 17:48:38

我使用以下新代码解决了这个错误

代码语言:javascript
运行
复制
 //in .h file

  //CHANGED WEAK PROPERTY TO RETAIN
  @property (retain, nonatomic) IBOutlet UIPickerView *pickerView;

 //in .m file
     //ADDED THESE LINES IN VIEWDIDLOAD
     _pickerView = [[UIPickerView alloc]init];
     _pickerView.delegate = self;
     _pickerView.dataSource = self;
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26899668

复制
相关文章

相似问题

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