2016-07-12 19 views
0

単一の値の配列を持つので、その単一の値をテキストファイルとして選択します。その単一の行の値を選択している間、ビューはスクロールしていて、ピッカーのビューはスクロールしているので、その単一の値を選択することはできません。ピッカービューで単一の値の配列を選択できない

私はその単一の行の値を選択することはできませんし、私はこのようにしようとした

ピッカービューdecleration

ProjectListpicker = [[UIPickerView alloc] initWithFrame:CGRectMake(325, 90, self.view.frame.size.width-500, 300)]; 
[ProjectListpicker setShowsSelectionIndicator:YES]; 
[ProjectListpicker selectRow:1 inComponent:0 animated:YES]; 
[ProjectListpicker reloadAllComponents]; 
ProjectListpicker.delegate = self; 
ProjectListpicker.dataSource = self; 
ProjectListpicker.tag = 1; 
ProjectListpicker.backgroundColor=[UIColor yellowColor]; 
[ProjectListpicker selectRow:1 inComponent:0 animated:YES]; 
ProjectListpicker.alpha = 0; 
[CreatmeetingView addSubview:ProjectListpicker]; 

didSelectRow方法

Projectstxtfld.text=[PROJECT_NAMEArray objectAtIndex:row]; 
    _ProjId = [PROJECT_IDArray objectAtIndex:row]; 
    NSLog(@"propiid %@ %@",ProjectIdstr,_ProjId); 
    [ProjectListpicker removeFromSuperview]; 

に誰もがこの上で私を助けることができます問題?

+0

あなたのコードをチェックしてください。 [ProjectListpicker selectRow:1 inComponent:0 animated:YES]を2回追加しました。 –

+0

ya ..しかし私は削除..余分な行...まだ同じprb .. :( –

+0

あなたの完全なコードを表示する – user3182143

答えて

0

ちょうど私が一つだけdata.That持っPickerView.In arrayPickerのデリゲートメソッドを使用するために、私はあなたのquestion.Weのためのサンプルプロジェクトを試してみました

UIPickerView * ProjectListpicker = [[UIPickerView alloc] init]; 
    ProjectListpicker.frame = CGRectMake(5,70,150,300); 
    ProjectListpicker.tag = 1; 
    ProjectListpicker.delegate = self; 
    ProjectListpicker.showsSelectionIndicator = YES; 
    [self.view addSubview:ProjectListpicker]; 

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
    NSLog(@"%@",_pickerData[row]); 
} 
0

コードの下にiOS.Whenされていてみてください私は、行を選択コンポーネントから完全に動作し、textFieldで選択した行の値を取得します。

直接選択した行を設定し、その値を取得したいので、もしあなたが以下のcode.Here選択行が0

[ProjectListpicker selectRowでなければならない使用し、配列内の一つだけのデータを持っている:0 inComponent:0アニメーション:はい];

[ProjectListpicker selectRow:1 inComponent:0 animated:YES]の代わりに。

UIPickerView * ProjectListpicker = [[UIPickerView alloc]init]; 
ProjectListpicker.frame = CGRectMake(0, 315, 320, 216); 
ProjectListpicker.showsSelectionIndicator = YES; 
ProjectListpicker.dataSource = self; 
ProjectListpicker.delegate = self; 
[ProjectListpicker selectRow:0 inComponent:0 animated:YES]; 
[self.view addSubview:ProjectListpicker]; 

プラグママーク-PickerView委任

// tell the picker how many components it will have 
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 1; 
} 

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 
    return arrayPicker.count; 
} 

// tell the picker the title for a given component 
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    return [arrayPicker objectAtIndex:row]; 
} 

// tell the picker the width of each row for a given component 
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component 
{ 
    return 300; 
} 

// get Picker Value 
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
    @try { 
    textFldPickerValue.text = [arrayPicker objectAtIndex:row]; 
    NSLog(@"The textFldPickerValue.text is - %@",textFldPickerValue.text); 
    } 
    @catch (NSException *exception) { 

    } 
} 
関連する問題