[ios]UIPickView use

1. Place UI controls on the storyboard and link with controller.m

 

2. Inherit <UIPickerViewDataSource, UIPickerViewDelegate> on controller.h

 

3.

-(void)initView{
    
    _cell_label_list = [NSArray arrayWithObjects:@"Devices",@"WiFi 2.4GHZ",@"WiFi 5GHZ",@"WiFi Strength"
                                    ,@"Guest Network",@"Setting",@"Iot", nil];
    
    _numberPicker.showsSelectionIndicator = YES;
    _numberPicker.dataSource = self;
    _numberPicker.delegate = self;

}

 
 4.

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

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
        return [_cell_label_list count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return [_cell_label_list objectAtIndex:row];
}

 

4. Default display:

//_channelValue is an Array
NSInteger channelTag = [_channelValue indexOfObject:channel];
[_numberPicker selectRow:channelTag inComponent:0 animated:YES];

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326408441&siteId=291194637