How to set a default Value of a UIPickerView

前端 未结 7 1170
刺人心
刺人心 2020-12-13 05:42

I have a problem with my UIPickerView. I have 3 values in it EU AP and NA. When I start the app EU seems to be selected but when I make a NSLog(@\"%@\", [regions objec

7条回答
  •  有刺的猬
    2020-12-13 06:19

    For example: you populated your UIPickerView with array values, then you wanted 
    

    to select a certain array value in the first load of pickerView like "Arizona". Note that the word "Arizona" is at index 2. This how to do it :) Enjoy coding.

    NSArray *countryArray =[NSArray arrayWithObjects:@"Alabama",@"Alaska",@"Arizona",@"Arkansas", nil];
    UIPickerView *countryPicker=[[UIPickerView alloc]initWithFrame:self.view.bounds];
    countryPicker.delegate=self;
    countryPicker.dataSource=self;
    [countryPicker selectRow:2 inComponent:0 animated:YES];
    [self.view addSubview:countryPicker];
    

提交回复
热议问题