2014-10-17 184 views
0

UIPickerView不工作在IOS 8,但它的工作在IOS 7没有错误,这里是我的代码 一个阵列,具有名字myArray的载荷pickerviewUIPickerView不工作在IOS 8

- (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

你是否正在使用工作表来显示选取器? – 2014-10-17 10:11:06

+0

不,只显示Picker View – Ujesh 2014-10-17 10:23:19

回答

0

我解决了这个问题,通过编程取代视图,问题在我看来,因为我创建了两个视图一个是主要的和se cond是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; 
} 

和其他代码是相同的......它在这两个操作系统的工作。

0

尝试一个如果两件事。

  1. viewdidLoad方法删除

    [sliderView addSubview:_myPickerView];

此代码。

  • 如果不是把这些代码拿过来,页头和初始化您鉴于pickerview做负载方法

    _myPickerView = [UIPickerVuew alloc]init]

  • -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]; 
    }