【问题标题】:Customizing EKEventViewController自定义 EKEventViewController
【发布时间】:2012-09-19 02:26:19
【问题描述】:

我看到这个应用程序似乎正在自定义 EKEventViewController。看起来它正在修改 EKEventViewController 中的 tableview 并向其附加行。它绝对不仅仅是它前面的一个视图 - 它实际上是在 tableview 内部

任何想法如何做到这一点?这可以通过继承 EKEventViewController 来完成吗? 我尝试了子类化 - 但不知道如何将 numberofRowsInSection 推送到超类。

看来我应该能够继承 EKEventViewController 并像这样覆盖 UITableView 委托函数

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

但由于 EKEventViewController 不继承自 UITableViewContoller(它是一个 UIViewController) - 此代码将无法编译。

【问题讨论】:

    标签: ios subclassing


    【解决方案1】:

    想通了

    子类 EKEventViewController 然后在那个类 viewDidAppear 增加tableview中scrollview的垂直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)];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多