Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to select cells in JTACYearView #1236

Open
Stefanhym opened this issue Mar 24, 2020 · 1 comment
Open

how to select cells in JTACYearView #1236

Stefanhym opened this issue Mar 24, 2020 · 1 comment

Comments

@Stefanhym
Copy link

(Required) Version Number:
iOS 13.3

Description

Is there a way to select cells in JTACYearView through delegate like JTACMonthView?
I didn't find any available methods to do this.

Steps To Reproduce

Expected Behavior

Additional Context

@nilnilnull
Copy link

nilnilnull commented Apr 14, 2020

I created a hack to resolve this issue for now. No PR since there are a lot of edge cases that my hack would not solve so treat carefully:

In JTACYearViewDelegate.swift, under the JTACYearViewDelegate , add:

func didSelectIndexPath(indexPath: IndexPath)

In JTACCollectionYearViewDelegates.swift, add:

public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        calendarDelegate?.didSelectIndexPath(indexPath: indexPath)
 } 

and lastly, in your JTACYearViewDelegate implementation:

    func didSelectIndexPath(indexPath: IndexPath) {
        
        var month: Int = 0
        if indexPath.item < 13 {
            month = indexPath.item
        } else {
            // because year cells are counted as items, we have to remove them from the month count
            // i.e. if indexPath.item = 14, we are tapping on january of the second year since Dec = 12, second_year = 13, january = 14
            month = (indexPath.item - (indexPath.item / 12)) % 12
        }
        
        var year: Int = 0
        if indexPath.item < 13 {
            year = sDate.year
        } else {
            let yearsToAdd = Float(indexPath.item / 12).rounded(.up)
            year  = sDate.year + Int(yearsToAdd)
        }
        
        print("selected month: \(month)")
        print("selected year: \(year)")
  }

Notes:

  • sDate is the startDate of your year calendar.
  • This works when the year start on January.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants