2012-04-17 21 views
0

UIPctionsViewに埋め込まれたカスタムUIPickerViewが呼び出されたときに画面の半分まで表示されます。よく働く。問題は、最初に(すべてのデータが読み込まれた後に)選択されたときに、barrelPickerに選択肢として「最も可能性の高い」結果を表示させたいということです。
アクションシートに埋め込まれたカスタムピッカーを取得する前に、私はUIViewControllerに持っていて、ViewControllerのviewDidLoadメソッドで "showProbableResults"(私のカスタムメソッド)を呼び出していました。 UIPickerViewがロードされ、移動する準備が整いました。私が今この方法を呼び出すための同等の場所はありますか、私は全体のデザインを再考する必要がありますか?本質的に、私が必要とするのは、UIPickerViewがロードされた後にこれを呼び出す場所です。UIPickerController - 読み込み時に特定の選択肢を表示したい

- (void)startWithDelegate:(UIViewController <ImageProcessingDelegate> *)sender 

{ 
self.delegate = sender; 
self.showFirstBottle = YES; 
[self start]; 

}

- (void) start { 

self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose Something" 
                 delegate:self 
               cancelButtonTitle:nil 
              destructiveButtonTitle:nil 
               otherButtonTitles:nil]; 

[self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

NSLog(@"1.) About to alloc the picker"); 

self.vintagePicker = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
self.vintagePicker.showsSelectionIndicator = YES; 
self.vintagePicker.dataSource = self; 
self.vintagePicker.delegate = self; 

[self.actionSheet addSubview:self.vintagePicker]; 
[self.vintagePicker release]; 

UISegmentedControl *nextButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Next"]]; 
nextButton.momentary = YES; 
nextButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
nextButton.segmentedControlStyle = UISegmentedControlStyleBar; 
nextButton.tintColor = [UIColor blackColor]; 
[nextButton addTarget:self action:@selector(show:) forControlEvents:UIControlEventValueChanged]; 
[self.actionSheet addSubview:nextButton]; 
[nextButton release]; 

UISegmentedControl *backButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Back"]]; 
backButton.momentary = YES; 
backButton.frame = CGRectMake(10, 7.0f, 50.0f, 30.0f); 
backButton.segmentedControlStyle = UISegmentedControlStyleBar; 
backButton.tintColor = [UIColor blackColor]; 
[backButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventValueChanged]; 
[self.actionSheet addSubview:backButton]; 
[backButton release]; 

[self.actionSheet showInView:_delegate.parentViewController.tabBarController.view]; // show from our table view (pops up in the middle of the table) 
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 

}

+0

アクションシート/ピッカーはカスタムクラスですか?いくつかのコードを教えてください。 – AMayes

+0

はい私のアクションシートとピッカーは、NSObject のカスタムクラスです。上のコードは、それをキックオフします。 –

答えて

0

一つの選択肢はhereに示すように、再使用可能なピッカービューを作成し、その後任意のビューから@optional

-(void)setInitialPickerValueToRow:(int)i inComponent:(int)j animated:(BOOL)k{ 
    [pickerView selectRow:i inComponent:j animated:k]; 
} 

を呼び出しますコントローラまたはNSObject(あなたのUIActionSheetDelegateなど)。

次のようにあなたの他のオプションは、標準の事前に選択された選択を設定することです:

self.vintagePicker = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
self.vintagePicker.showsSelectionIndicator = YES; 
self.vintagePicker.dataSource = self; 
self.vintagePicker.delegate = self; 
[self.actionSheet addSubview:self.vintagePicker]; 
[self.vintagePicker selectRow:0 inComponent:0 animated:NO]; 

また、あなたは設定の異なる変数を持っている、とselectRow:inComponent:animated:アクセスそれらを持って、代わりにプリセットであることの可能性があります。

[self.vintagePicker selectRow:myRow inComponent:0 animated:NO]; 

これが役に立ちます。

+0

これは私があなたが探しているものを知っていると仮定しています。最初の選択範囲を設定したかったのですか、またはpickerViewを初期化する場所を特定しようとしていましたか? – AMayes

+0

最初の選択を設定するだけ!あなたの提案を試して、それが動作し、すぐに受け入れるかどうかを確認します - ありがとう! –

+0

私は残念ながらうまくいきませんでした。ピッカーはまだ行とコンポーネントを設定しており、例外をスローします。より明示的には、3つのコンポーネントピッカーにnsdisctionaryの変数をロードし、第2コンポーネントの値は第1コンポーネントの値に依存し、第3コンポーネントの値は第1コンポーネントと第2コンポーネントの値に依存します...だから、私は選択することができます前に、バレルピッカー全体がロードされ準備ができている必要があります。簡単な「UIPicker仕上げ読み込み」メソッドがあるかもしれないと思っていました。 –

関連する問題