DayFlow icon indicating copy to clipboard operation
DayFlow copied to clipboard

Selecting multiple dates

Open sigmundfridge opened this issue 11 years ago • 13 comments

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'.

sigmundfridge avatar May 27 '13 22:05 sigmundfridge

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

evadne avatar May 27 '13 22:05 evadne

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.

evadne avatar May 27 '13 22:05 evadne

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.

sigmundfridge avatar May 27 '13 22:05 sigmundfridge

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

evadne avatar May 27 '13 22:05 evadne

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

sigmundfridge avatar May 27 '13 22:05 sigmundfridge

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.

evadne avatar May 27 '13 22:05 evadne

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 avatar May 27 '13 23:05 sigmundfridge

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.

sigmundfridge avatar May 28 '13 00:05 sigmundfridge

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 [email protected] 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 .

evadne avatar May 28 '13 00:05 evadne

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.

sigmundfridge avatar Nov 16 '13 18:11 sigmundfridge

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 [email protected] 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 avatar Nov 16 '13 19:11 evadne

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 [email protected] 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

evadne avatar Nov 16 '13 19:11 evadne

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" [email protected] 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 [email protected] 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.

sigmundfridge avatar Nov 16 '13 19:11 sigmundfridge