2014-10-17 189 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]; 
    }