我使用selectedRowInComponent方法與指標0取得有關組件當前選擇的行,但它總是返回0。我已經在pickerview selectedRowInComponent總是返回0
NSLog("%d",[pickerview selectedRowInComponent:0]);
檢查的話我已經初始化撿拾工具,因爲我我以編程方式使用選取器視圖。請建議。
我使用selectedRowInComponent方法與指標0取得有關組件當前選擇的行,但它總是返回0。我已經在pickerview selectedRowInComponent總是返回0
NSLog("%d",[pickerview selectedRowInComponent:0]);
檢查的話我已經初始化撿拾工具,因爲我我以編程方式使用選取器視圖。請建議。
我希望這段代碼能幫助你。我在我的項目中使用它,它的工作非常完美。
調用此函數它的viewDidLoad
[self loadFirstPicker];
下面是功能,使UIpicker其中僅顯示時間。 (和文本中費爾德保存)
-(void)loadFirstPicker
{
UIDatePicker *picker = [[UIDatePicker alloc] init];
picker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
picker.datePickerMode = UIDatePickerModeTime;
[picker addTarget:self action:@selector(dueDateChanged:) forControlEvents:UIControlEventValueChanged];
CGSize pickerSize = [picker sizeThatFits:CGSizeZero];
picker.frame = CGRectMake(0.0, 250, pickerSize.width, 460);
picker.backgroundColor = [UIColor blackColor];
checkEveryTextFeild.inputView = picker;
//[self.view addSubview:picker];
//[picker release];
// Create done button in UIPickerView
UIToolbar* mypickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 220, 56)];
mypickerToolbar.barStyle = UIBarStyleBlackOpaque;
[mypickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked)];
[barItems addObject:doneBtn];
[mypickerToolbar setItems:barItems animated:YES];
checkEveryTextFeild.inputAccessoryView = mypickerToolbar;
}
這一功能正從拾取時間,將其設置爲textFeild
-(void) dueDateChanged:(UIDatePicker *)sender {
NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"HH:mm:ss"];
//[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
checkEveryTextFeild.text = [dateFormatter stringFromDate:[sender date]];
NSDate *currentDate = [NSDate date];
NSLog(@"%@",currentDate);
NSLog(@"Picked the date %@", [dateFormatter stringFromDate:[sender date]]);
}
你可能想嘗試設置他們兩個。
[filterPicker selectRow:selectedPickerIndex inComponent:0 animated:NO];
[self pickerView:filterPicker didSelectRow:selectedPickerIndex inComponent:0];
self.personInfoPicker.delegate = self;
self.personInfoPicker.dataSource = self;
[self.personInfoPicker reloadAllComponents];
也許pickerview ==零則selectedRowInComponent將是0,也沒有 – NeverBe
它不是零:該類檢測第二線將檢索pickerview。當我們在控制檯中打印它。它正在響應類名稱和幀大小。 – Arvind
您是否將變量連接到插座?你使用多少個採樣器? – NeverBe