evadne / DayFlow

iOS Date Picker + Infinite Scrolling
229 stars 21 forks source link

Selecting multiple dates #3

Open sigmundfridge opened 11 years ago

sigmundfridge commented 11 years ago

Hi, Loving the calendar. I needed to select multiple dates. To do this I subclassed DFDatePickerView, and overwrote the following methods....

- (UICollectionView *) collectionView;
- (DFDatePickerDayCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
- (void) collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath: (NSIndexPath *)indexPath;
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;

Nothing to complicated, just adding/removing dates to an array and changing how a cell is displayed based on that array. Then I subclassed DFDatePickerViewController, and overwrote -(DFDatePickerView*) datePickerView to use my new subclass. An extra method in the protocol passes the array to the delegate.

This all worked fine when using it within your own dayFlow-sample project. Strangely, when moving the files over to my own project the calendar always opens 6 months in the past. I know you use +/- 6 months when first generating the collection view. However, I can't see why my project would start there, but the same code in your sample project starts in the middle (i.e. now).

I realise this is out of the scope of your project, but if you can think of any reasons why the same code in 2 apps would behave differently I would be very appreciative. Either way, I'd suggest considering allowing multiple dates to be selected, as it seems to be a gap in the 'market'.

evadne commented 11 years ago

I think this is why — is there double initialization happening?

evadne commented 11 years ago

Also would love to get a patch for multiple date selection — if we can work out a nice API this will be a great thing to have :) thanks for using DayFlow.

sigmundfridge commented 11 years ago

I can send you my code, but I am towards the amateur end of the spectrum so it might not be much use. It is potentially a very simple problem, but being relatively new to Objective C my subclassing is still a bit guesswork.

evadne commented 11 years ago

I happen to have approximately 15 minutes — can you put me on the repo as a temporary collaborator?

sigmundfridge commented 11 years ago

and thanks for the help, that definitely looks like the issue

evadne commented 11 years ago

You can just tell the collection view to scroll to the middle (reuse that chunk of code in -viewWillMoveToSuperview:) in your view controller’s -viewWillAppear:. That might work.

sigmundfridge commented 11 years ago

Sorry for the delay, I hadn't actually added a repo for it (as it was just something I was messing around with). I've uploaded it now, and added you as a collaborator. It is basically your sample project, so needs pod install (the podfile is already present). If you don't get a chance to look at it, I will take your advice and work on it later.

sigmundfridge commented 11 years ago

That works in viewDidAppear but not 'will' . And obviously this causes a bit of a jump. It also seems that this isn't just an issue for my subclassing, but generally when initialising your view controller via the storyboard.

evadne commented 11 years ago

Gotcha. Storyboard usage. I will look at that and try to make the date scrolling less hacks.

On May 27, 2013, at 17:20, sigmundfridge notifications@github.com wrote:

That works in viewDidAppear but not 'will' . And obviously this causes a bit of a jump. It also seems that this isn't just an issue for my subclassing, but generally when initialising your view controller via the storyboard.

— Reply to this email directly or view it on GitHubhttps://github.com/evadne/DayFlow/issues/3#issuecomment-18518949 .

sigmundfridge commented 10 years ago

Hi again, Finally got around to formalising multiple date selection, and I've added you as a contributor to the forked project. When you initialise the view controller you send a BOOL to determine if it's single or multiple date selection. It defaults to single. It seems like a pretty simple addition to me, but I might be missing some finer important points from your code.

evadne commented 10 years ago

I think we shall just expose the underlying collection view as multiple selection and adjust the public API correctly?

On Nov 17, 2013, at 2:19, sigmundfridge notifications@github.com wrote:

Hi again, Finally got around to formalising multiple date selection, and I've added you as a contributor to the forked project. When you initialise the view controller you send a BOOL to determine if it's single or multiple date selection. It defaults to single. It seems like a pretty simple addition to me, but I might be missing some finer important points from your code.

— Reply to this email directly or view it on GitHubhttps://github.com/evadne/DayFlow/issues/3#issuecomment-28632397 .

evadne commented 10 years ago

ALSO — if you send a pull request I’ll be so happy to review it formally :)

On Nov 17, 2013, at 2:19 AM, sigmundfridge notifications@github.com wrote:

Hi again, Finally got around to formalising multiple date selection, and I've added you as a contributor to the forked project. When you initialise the view controller you send a BOOL to determine if it's single or multiple date selection. It defaults to single. It seems like a pretty simple addition to me, but I might be missing some finer important points from your code.


Reply to this email directly or view it on GitHub: https://github.com/evadne/DayFlow/issues/3#issuecomment-28632397

sigmundfridge commented 10 years ago

I think that's basically what i did, but added a custom init to allow for single or multiple selection.

Sent from my iPad

On Nov 16, 2013, at 7:03 PM, "Evadne Wu" notifications@github.com wrote:

I think we shall just expose the underlying collection view as multiple selection and adjust the public API correctly?

On Nov 17, 2013, at 2:19, sigmundfridge notifications@github.com wrote:

Hi again, Finally got around to formalising multiple date selection, and I've added you as a contributor to the forked project. When you initialise the view controller you send a BOOL to determine if it's single or multiple date selection. It defaults to single. It seems like a pretty simple addition to me, but I might be missing some finer important points from your code.

— Reply to this email directly or view it on GitHubhttps://github.com/evadne/DayFlow/issues/3#issuecomment-28632397 . — Reply to this email directly or view it on GitHub.