[英]iOS UIPickerView how to get the selected row
The value of the array is this 数组的值是这个
ListArray = [[NSMutableArray alloc] init];
ListArray = [NSMutableArray arrayWithObjects:@"Google", @"Samsung", @"Twitter", @"Facebook", @"Apple", @"NiKon", nil];
And when you click on the selectButton 当您单击selectButton时
NSString *select = [ListArray objectAtIndex:[_picker selectedRowInComponent:0]];
NSString *title = [[NSString alloc] initWithFormat:@"Select : %@", select];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
Receive a message box. 收到一个消息框。 When you press OK, I want to go to select the value of the selected file. 当您按OK时,我要去选择所选文件的值。
But select value is 0. 但选择值为0。
I do not know how. 我不知道怎么。
You can implement UIPickerViewDelegate
in your class and you will get an event when the user selects a row in a component: 您可以在您的类中实现UIPickerViewDelegate
,当用户在组件中选择一行时,您将获得一个事件:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// here you can remember the selected row or perform some action
}
Don't forget to set your pickerView delegate: 不要忘记设置您的pickerView委托:
self.pickerView.delegate = self; // or other
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *selectedValue=[ListArray objectAtIndex:row]];
NsLog(@"selectedValue:%@",selectedValue);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.