Search code examples
iossubclassing

Customizing EKEventViewController


i've seen this app that appears to be customizing the EKEventViewController. It looks like it's modifying the tableview in EKEventViewController and appending rows to it. It's definitely not just a view in front of it - it's actually inside the tableview

custom EKEventViewController

Any ideas how this is done? Can this be done through subclassing EKEventViewController? I've tried subclassing - but can't figure out how to push numberofRowsInSection to the super class.

It's seems I should be able to subclass EKEventViewController and override the UITableView delegate functions like this

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [super tableView:tableView numberOfRowsInSection:section];
}

But since EKEventViewController doesn't inherit from UITableViewContoller (it's a UIViewController) - this code will not compile.


Solution

  • Figured it out by

    subclass EKEventViewController then in that class viewDidAppear increase vertical contentSize of scrollview in the tableview add in my little view controller after the end of the last row

    +(void) viewDidAppear:(BOOL)animated
        {
        if ([self.event.location length]>0)
        {
                UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
            _mev = (MapEventView*)[mainStoryboard instantiateViewControllerWithIdentifier: @"MAP_EVENT_VIEW"];
    
            UITableView* tv=[self getEKEventTableView];
            //tv.showsVerticalScrollIndicator=YES;
            tv.contentSize=CGSizeMake(tv.contentSize.width, tv.contentSize.height+MAP_EVENT_VIEW_PADDING+_mev.view.frame.size.height);
    
            // get last row in last sectoin
            int lastSection=[tv numberOfSections]-1;
            int lastRow=[tv numberOfRowsInSection:lastSection]-1;
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lastRow inSection:lastSection];
            UITableViewCell* cell=[tv cellForRowAtIndexPath:indexPath];
    
            float mapeventview_origin=cell.frame.origin.y+cell.frame.size.height;
    
            TGLog(@"%d,%d %f %f", lastSection, lastRow, cell.frame.origin.y, mapeventview_origin);
            TGLog(@"event %@ location %@", self.event.title, self.event.location);
            _mev.ewc=[[EKEventWithCoords alloc] init];
            _mev.ewc.event=self.event;
    
            [tv addSubview:_mev.view];
            [_mev.view setCenter:CGPointMake(_mev.view.center.x, _mev.view.center.y+mapeventview_origin)];
        }
    }