2
It is possible to make a selection list (UIPickerView
) in loop form? Put the month of January right after December, I say.
2
It is possible to make a selection list (UIPickerView
) in loop form? Put the month of January right after December, I say.
1
Just like the @Rivas
said, there is no very practical way to do it. I’ll try to illustrate a little better the explanation above:
You need to multiply the amount of elements by a high number, 100, for example, but be careful, because depending on the object used, multiplying by a very high number can cause slowness.
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return self.mesesArray.count * 100;
}
Then to get the title correctly it is necessary to use the operator mod
(%
) to obtain the 12-month line.
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return self.mesesArray[row % self.mesesArray.count];
}
And to finish position the selection of UIPicker
through the middle of the list, or some next line. Do this in some view startup method, such as the viewDidLoad
.
- (void)viewDidLoad
{
[super viewDidLoad];
self.mesesArray = @[@"Janeiro",@"Fevereiro",@"Março",@"Abril",@"Maio",@"Junho",@"Julho",@"Agosto",@"Setembro",@"Outubro",@"Novembro",@"Dezembro"];
[self.pickerView selectRow:self.mesesArray.count * 50
inComponent:0
animated:NO];
}
The final result this:
1
Yes, but the method is kind of gambiarra, there is an automatic code for it so much that apple itself does. I’ll explain; Smplismente make a list of 100 copies of the same sequence, then make this Picker move to sequence #50( item #50*12 months).
Browser other questions tagged ios objective-c
You are not signed in. Login or sign up in order to post.