我有一個自定義的UIPickerView嵌入到一個UIActionsheet中,當調用時它會出現在屏幕的一半。很棒。問題在於我想讓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)];
}
您的行動表/選取器是一個自定義類嗎?請給我們一些代碼。 – AMayes 2012-04-17 14:42:39
是的,我的動作表和選取器是NSObject的一個自定義類 - 上面的代碼是將它踢開的。 –
2012-04-17 15:05:07