I want to make a Picker View and it will be displayed when I click a button, my code as below, but the picker view show nothing, what can I do?
Code:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 20;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [NSString stringWithFormat:@"%@-%d", component == 1 ? @"R" : @"L", row];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
UIPickerView *pickerView = (UIPickerView *)[actionSheet viewWithTag:101];
self.title = [NSString stringWithFormat:@"L%d-R%d-L%d", [pickerView selectedRowInComponent:0], [pickerView selectedRowInComponent:1], [pickerView selectedRowInComponent:2]];
[actionSheet release];
}
- (void)action {
NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Set Combo", nil];
[actionSheet showInView:self.view];
UIPickerView *pickerView = [[[UIPickerView alloc] init] autorelease];
pickerView.tag = 101;
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
[actionSheet addSubview:pickerView];
// Peek at dimensions
CFShow(NSStringFromCGRect(pickerView.frame));
}