简体   繁体   English

自定义 EKEventViewController

[英]Customizing EKEventViewController

i've seen this app that appears to be customizing the EKEventViewController.我见过这个应用程序似乎在自定义 EKEventViewController。 It looks like it's modifying the tableview in EKEventViewController and appending rows to it.看起来它正在修改 EKEventViewController 中的 tableview 并向其附加行。 It's definitely not just a view in front of it - it's actually inside the tableview它绝对不仅仅是它前面的一个视图——它实际上是在 tableview 里面

自定义 EKEventViewController

Any ideas how this is done?任何想法如何做到这一点? Can this be done through subclassing EKEventViewController?这可以通过继承 EKEventViewController 来完成吗? I've tried subclassing - but can't figure out how to push numberofRowsInSection to the super class.我试过子类化 - 但不知道如何将 numberofRowsInSection 推送到超类。

It's seems I should be able to subclass EKEventViewController and override the UITableView delegate functions like this看来我应该能够子类化 EKEventViewController 并像这样覆盖 UITableView 委托函数

- (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.但是由于 EKEventViewController 不是从 UITableViewContoller 继承的(它是一个 UIViewController) - 此代码将无法编译。

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子类 EKEventViewController 然后在该类 viewDidAppear 增加 tableview 中滚动视图的垂直 contentSize 在最后一行结束后添加我的小视图控制器

+(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)];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM