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

Detect Empty Time Slots #19

Open
RizITN opened this issue Jan 1, 2014 · 3 comments
Open

Detect Empty Time Slots #19

RizITN opened this issue Jan 1, 2014 · 3 comments

Comments

@RizITN
Copy link

RizITN commented Jan 1, 2014

Hi,
I have a requirement that user could add events against the empty slots. Whenever user select any empty slot, its corresponding time slot should be selected as StartTime, then add the other information via custom view.

So is it possible we can detect empty slots?

Thanks & Regards

@SharatGuduru44
Copy link

implementing this method in MAGridView (MAWeekViewAdditions) i got the start time and end time for empty slot.
iam not sure if this approach is write or wrong as i am new to ios Development.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    self.weekView=[MAWeekView new];
        const double posX = _touchX.x / self.cellWidth;
        const double posY = _touchX.y / self.cellHeight;
        
                
        /* Calculate the new time for the event */
        
//      const int eventDurationInMinutes = [self.event durationInMinutes];
        NSDate *weekday = [self.weekView.weekdayBarView.weekdays objectAtIndex:(int)round(posX)];
        double hours;
        double minutes;
        minutes = modf(posY, &hours) * 30;
    
        NSDateComponents *startComponents = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:weekday];
        [startComponents setHour:(int)hours];
        [startComponents setMinute:[self modifiedMinutes:minutes]];
        [startComponents setSecond:0];
        
        [EventManger instance].startTime = [CURRENT_CALENDAR dateFromComponents:startComponents];
        [EventManger instance].endTime   = [[EventManger instance].startTime dateByAddingTimeInterval:60];
//      self.event.displayDate = [CURRENT_CALENDAR dateFromComponents:startComponents];
        
        
        
        
        return;
    
    [super touchesEnded:touches withEvent:event];
}

@stefanocdn
Copy link

Was trying to perform same thing, but new to ios as well. Does this solution works for you?

@JordanMontel
Copy link

Hi,
I had the same problem and I fixed this by adding a gesture recognizer to the weekView in WeekViewController.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // WeekView
    self.weekView = (MAWeekView *)self.view;

    // Touch grid with gesture recognizer
    self.singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [self.singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [self.weekView addGestureRecognizer:self.singleTapGestureRecognizer];
}

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
    // Point position
    CGPoint touch = [recognizer locationInView:self.weekView];
    const double posX = touch.x / self.weekView.gridView.cellWidth;
    const double posY = touch.y / self.weekView.gridView.cellHeight;

    // Current date
    NSDate *weekday = [self.weekView.weekdayBarView.weekdays objectAtIndex:(int)round(posX)];
    double hours;
    double minutes;
    minutes = modf(posY, &hours) * 30;

    NSDateComponents *startComponents = [CURRENT_CALENDAR components:DATE_COMPONENTS fromDate:weekday];
    [startComponents setHour:(int)hours];
    [startComponents setMinute:minutes];
    [setSecond:0];

    NSDate *currentDate = [CURRENT_CALENDAR dateFromComponents:startComponents];
    NSLog(@"%@", currentDate);
}

But, you need to modify MAWeekView.h by adding the property from .m :

@property (readonly) MAGridView *gridView;
@property (readonly) MAWeekdayBarView *weekdayBarView;

and

@protocol MAWeekViewDelegate <NSObject>

@optional
- (void)weekView:(MAWeekView *)weekView eventTapped:(MAEvent *)event;
- (void)weekView:(MAWeekView *)weekView weekDidChange:(NSDate *)week;
- (void)weekView:(MAWeekView *)weekView eventDragged:(MAEvent *)event;
- (BOOL)weekView:(MAWeekView *)weekView eventDraggingEnabled:(MAEvent *)event;

@end

@interface MAWeekdayBarView : UIView {
    MAWeekView *_weekView;
    NSDate *_week;
    UIColor *_textColor, *_sundayColor, *_todayColor;
    UIFont *_textFont;
    NSDateFormatter *_dateFormatter;
    NSMutableArray *_weekdays;
}

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

4 participants