0

“我正在为 iPhone 创建一个应用程序,我必须在其中创建一个登录页面。从服务器获得响应后..它将导航用户到下一个视图。在下一个视图中,我使用 UIPickerView。但它不工作.. 因为我只知道如何在单个应用程序中使用它。但我不知道如何在应用程序的第二个 ViewController 中使用它??”

4

2 回答 2

1

你可以使用这个 getPicker

-(void)getValuePicker
{
    ViewForValuePicker = [[UIView alloc]initWithFrame:CGRectMake(0, 219, 320, 266)];

    UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    toolBar.barStyle = UIBarStyleBlackOpaque;

    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneBtnPressToGetValue)];

    [toolBar setItems:[NSArray arrayWithObject:btn]];
    [ViewForValuePicker addSubview:toolBar];


    valuePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
    valuePicker.delegate=self;
    valuePicker.dataSource=self;
    valuePicker.showsSelectionIndicator=YES;

    [ViewForValuePicker addSubview:valuePicker];

    [appDelegate.window addSubview:ViewForValuePicker];
}  

及其委托方法

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
    return [pickerValueAry count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
    NSMutableArray *ary = [[NSMutableArray alloc] initWithArray:pickerValueAry];
    id str=[ary objectAtIndex:row];
    return str;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{    
    NSLog(@"selectedRowInPicker >> %d",row);
}
于 2012-11-23T07:26:56.897 回答
0
in .h file  this method

 UIViewController<UIPickerViewDataSource,UIPickerViewDelegate>

{

    IBOutlet UIPickerView *picker;
     NSMutableArray *pickerArrayType;
}

//in .m file

- (void)viewDidLoad
{
    [super viewDidLoad];
pickerArrayType = [[NSMutableArray alloc] initWithObjects:@"Type 1",@"Type 2",@"Type 3",@"Type 4",@"Type 5", nil]
}


# pragma mark - picker Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1;
}

- (void)pickerView:(UIPickerView *)pickerView1 didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{


 lbl.text = [pickerArrayType objectAtIndex:row];

}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
  return [pickerArrayType count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
    return [pickerArrayType objectAtIndex:row];
}
于 2012-11-23T06:54:10.147 回答