我有一个应用程序,当用户单击一个按钮时,我想打开 uipickerview 作为主视图的子视图,并且在用户选择一个项目后,它应该从主视图中删除。(下拉类型的功能)。为此我编写了代码如下:
-(void)showPrefPicker:(id)sender
{
UIView *subView=[[UIView alloc] init];
subView.frame=CGRectMake(180, 120, 150, 150);
pickerView = [[UIPickerView alloc] init];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
pickerView.frame=CGRectMake(190, 130, 100, 100);
subView.backgroundColor=[UIColor blackColor];
[subView addSubview:pickerView];
[self.view addSubview:subView];
[pickerView release];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 1;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(@"selected object is %@",[arraypref objectAtIndex:row]);
//[pickerView ]
//mlabel.text= [arrayNo objectAtIndex:row];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
return [arraypref count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
return [arraypref objectAtIndex:row];
}
但只在主视图中显示子视图而不是pickerview。我该怎么做任何教程或源代码?