[英]iOS UIPickerView how to get the selected row outside the delegate method
[英]iOS UIPickerView how to get the selected row
數組的值是這個
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。
我不知道怎么。
您可以在您的類中實現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
- (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.