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)
答案 0 :(得分:0)
如果有两件事,请尝试一下。
删除
[sliderView addSubview:_myPickerView];
此代码来自viewdidLoad
方法。
如果这不起作用,请将该代码重新放入并在视图中分配并初始化您的选择器视图加载方法
_myPickerView = [UIPickerVuew alloc]init]
答案 1 :(得分:0)
我通过编程选择器查看来解决这个问题,问题在我的视图中,因为我创建了两个视图,一个是主视图,第二个是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;
}
和其他代码相同......它在两个操作系统中都有效。
答案 2 :(得分:-1)
尝试..
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
alertController = [UIAlertController alertControllerWithTitle:nil
message:@"\n\n\n\n\n\n\n\n\n\n"
preferredStyle:UIAlertControllerStyleActionSheet];
//pickerView.frame=CGRectMake(0, 0, 120, 30);
UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 305.0f, 44.f)];
toolView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blank-headerNew.png"]];
CGRect buttonFrame = CGRectMake(220, 5, 70, 30);
UIButton *selButton = [[UIButton alloc] initWithFrame:buttonFrame];
//[selButton setBackgroundImage:[UIImage imageNamed:@"red_bgnew.png"] forState:UIControlStateNormal];
[selButton setTitle:@"Done" forState:UIControlStateNormal];
[selButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[toolView addSubview:selButton];
[alertController.view addSubview:pickerView];
[alertController.view addSubview:toolView];
[self presentViewController:alertController animated:YES completion:nil];
}