UIPickerView在IOS 8中不工作

UIPickerView在IOS 8中不工作,ios,iphone,ios7,ios8,uipickerview,Ios,Iphone,Ios7,Ios8,Uipickerview,UIPickerView在IOS 8中不工作,但在IOS 7中工作没有错误,这是我的代码 一个名为myArray的数组在pickerview中加载数据 - (void)viewDidLoad { [sliderView addSubview:_myPickerView]; txtstreet.inputView=_myPickerView; myArray = arrwithdata; } - (NSInteger)numberOfComponentsInPickerV

UIPickerView在IOS 8中不工作,但在IOS 7中工作没有错误,这是我的代码 一个名为myArray的数组在pickerview中加载数据

- (void)viewDidLoad
{
   [sliderView addSubview:_myPickerView];

    txtstreet.inputView=_myPickerView;
    myArray = arrwithdata;
}

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

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{

 return [myArray count];

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)rowForComponent:(NSInteger)component
{
    return myArray[row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component 
{

    NSString *resultString = [[NSString alloc] initWithFormat:@"%@", myArray[row]];
    txtstreet.text = resultString;
}
它在ios7中运行 在IOS 8设备中运行时出现以下错误

2014-10-17 11:54:19.284 DispatchMe[2119:903697] *** Terminating app due to uncaught       
exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:   
 <UICompatibilityInputViewController: 0x145553dc0> should have parent view controller: 
 <RegistrationVC: 0x14560e930> but requested parent is:<UIInputWindowController: 
0x146037a00>'
 ***  First throw call stack:

(0x183e8e084 0x19446c0e4 0x183e8dfc4 0x1886aa688 0x188d09e14 0x188d0a968 0x18861e77c  
 0x188d0a794 0x188d06924 0x1886d2180 0x188691b3c 0x188691e10 0x1887114e8 0x1887c2288 0x1887c18f0 0x1887a7768 0x188640184 0x188aa8f78 0x18860475c 0x188602b08 0x18863e32c 0x18863d9cc 0x1886111d4 0x1888af98c 0x18860f73c 0x183e46324 0x183e455c8 0x183e43678 0x183d71664 0x18ceb35a4 0x1886764f8 0x100058068 0x194adaa08)
 libc++abi.dylib: terminating with uncaught exception of type NSException
 (lldb) 

如果有两件事,就试一件

除去

[sliderView添加子视图:_myPickerView]

此代码来自viewdidLoad方法

若这不起作用,那个么将代码放回并alloc和init,视图中的pickerview确实加载了方法

_myPickerView=[UIPickerVuew alloc]init]

试试


我通过编程方式创建picker视图来解决这个问题,问题在我的视图中,因为我创建了两个视图,一个是main,另一个是sliderview,从视图调用picker来创建sliderview, 现在我的代码是这样的

 - (void)viewDidLoad
{
 UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
 //[sliderView addSubview:_myPickerView];

txtstreet.inputView=_myPickerView;
myArray = arrwithdata;
}

和其他代码是一样的。。。这在两个操作系统中都是可行的。

您是否使用Actionsheet来显示Picker?不,只显示Picker视图
 - (void)viewDidLoad
{
 UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
 //[sliderView addSubview:_myPickerView];

txtstreet.inputView=_myPickerView;
myArray = arrwithdata;
}