私は、ユーザーが時間を入力しているピッカービューを持っています。 23時までスクロールすると、次のアイテムとして時間ゼロが表示され、シーケンスが再開されます。どうすればこれを達成できますか?ここで「無限の」UIPickerViewを作成するにはどうすればよいですか?
が私の現在のピッカービューデータソースである:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSArray *sectionContents = [[self dataForDatapickerRows] objectAtIndex:component];
NSInteger rows = [sectionContents count];
NSLog(@"component %d rows is: %d",component,rows);
return rows;
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
self.dataPickerInstance.backgroundColor=[UIColor whiteColor];
return ([[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]);
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if(component==0)
{
[self setHou:(NSInteger*)[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]];
}
else if(component==1)
{
[self setMinut:(NSInteger*)[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]];
}
else if(component==2)
{
[self setSecon:(NSInteger*)[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]];
}
NSLog(@"%@",[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row]);
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
[tView setFrame:CGRectMake(0, 0, 90,60)];
tView.self.textColor=[UIColor whiteColor];
tView.minimumFontSize = 80;
tView.textAlignment=UITextAlignmentCenter;
tView.adjustsFontSizeToFitWidth = YES;
tView.autoresizesSubviews=YES;
tView.font = [UIFont boldSystemFontOfSize:40];
tView.backgroundColor = [UIColor blackColor];
//tView.highlightedTextColor=[UIColor greenColor];
// factLabel.frame = CGRectMake(factLabel.frame.origin.x, factLabel.frame.origin.y, factLabel.frame.size.width, lLabelSIze.height);
//
// Setup label properties - frame, font, colors etc
} // Fill the label text here
tView.text=[[[self dataForDatapickerRows ]objectAtIndex:component] objectAtIndex:row];
return tView;
}
こんにちは友人、私はあなたのコードをyou.Inためにありがとうを言う必要がある最初の事を18000まで数えますが、私は24時間しか必要とせず、秒と60分しか必要としません。あなたは何か考えていますか? – Spynet
を共有してください。まず、すべてのメソッド(am/pm)の最後のコンポーネントを削除します。次に、あなたのニーズに合わせて 'pickerView:titleForRow:forComponent:'を変更する必要があります(例えば、 'NSString stringWithFormat:@"%d "、row%24" 'を使用して0〜 1と24の間の値をとるには '[NSString stringWithFormat:@"%d "、行%24 + 1]'を使用します)。秒と分はすでに0と59の間の値しか取っていません。 'user792677'のポストからのリンクをチェックしてください。より良い説明ができます(同じアイデアを使用し、新しい値が選択された後に中央にスクロールします)。 –
ああ..同じ値を返すために 'pickerView:didSelectRow:inComponent:'を変更する必要もあります( 'component == 0' '_h'(時)の最初のif - am/pm - を削除します) %24(または行%24 + 1は、 'titleForRow:'メソッドでどのように使用するかによって異なります) –