数组的值是
ListArray = [[NSMutableArray alloc] init];
ListArray = [NSMutableArray arrayWithObjects:@"Google", @"Samsung", @"Twitter", @"Facebook", @"Apple", @"NiKon", nil];
当你点击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];
收到一个消息框。 当您按OK时,我想去选择所选文件的值。
但是选择值为0。
我不知道怎么做。
答案 0 :(得分:1)
您可以在班级中实施UIPickerViewDelegate
,当用户在某个组件中选择一行时,您会收到一个事件:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// here you can remember the selected row or perform some action
}
不要忘记设置pickerView委托:
self.pickerView.delegate = self; // or other
答案 1 :(得分:1)
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *selectedValue=[ListArray objectAtIndex:row]];
NsLog(@"selectedValue:%@",selectedValue);
}