开发者

How can pickerview have date component to it?

I need to add a date component to my PickerView. Any ideas on how to get the date component? One way is to manually maintain all the date related info, take current date add and subtract to get the reqd dates, but this is very tedious, any other methods?

How can pickerview have date component to it?

EDIT:I have not yet got about to writing the code, i need some ideas on how to go about getting the values for the date component(not UI). One solution I have 开发者_JAVA百科is to take the current date and then use the 'dateByAddingTimeInterval' to maintain the the last 50 and next 50 days, but his approach is very crude. Is there a better way to do this?


Going from comments here:

I suggest you to try this one approach.

  1. Creating one UIPickerView.
  2. Setting its parameters (step 1 in class that implements UIPickerViewDataSource):
    1. Implement - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView that will provide number of components. In your case it is 3 : return 3;
    2. Implement - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component that will return the number of row for each component.
  3. Setting its parameters (step 1 in class that implements UIPickerViewDelegate):
    1. Implement - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view which will return UILabel for component 0 and 1 and UIView with two UILabel's as subview (gray one and black one) for component 2

Also you can make more customization by implementing other methods in delegate class:

Setting the Dimensions of the Picker View

– pickerView:rowHeightForComponent:
– pickerView:widthForComponent:

Setting the Content of Component Rows

– pickerView:titleForRow:forComponent:

Complete list of methods you can find here: UIPickerViewDelegate Protocol Reference


I went ahead and used the same approach that i had mentioned in the question(given below). Even though its crude, it gets the work done. I have not tested this approach for large values of date in the third component. As of now i just have (30+30) values including the current date and its pretty stable and quick.

"One solution I have is to take the current date and then use the 'dateByAddingTimeInterval' to maintain the the last 50 and next 50 days, but his approach is very crude."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜