繁体   English   中英

在弹出视图中做出选择后尝试关闭表格

[英]Trying to dismiss table when a selection has been made in popup View

我从ViewController.m调用

当我从弹出窗口中选择一行时,我试图调用下面的控制器

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    ...

    TSPopoverController *dismiss = [[TSPopoverController alloc]init];
    [dismiss dismissPopoverAnimatd:YES];



}

在以下类别中找到:TSPopoverController.m

- (void) dismissPopoverAnimatd:(BOOL)animated
{
    if (self.view) {
        if(animated) {
            [UIView animateWithDuration:0.2
                                  delay:0.0
                                options:UIViewAnimationOptionAllowAnimatedContent
                             animations:^{
                                 popoverView.alpha = 0;
                             }
                             completion:^(BOOL finished) {
                                 [self.contentViewController viewDidDisappear:animated];
                                 popoverView=nil;
                                 [self.view removeFromSuperview];
                                 self.contentViewController = nil;
                                 self.titleText = nil;
                                 self.titleColor = nil;
                                 self.titleFont = nil;
                             }
             ];
        }else{
            [self.contentViewController viewDidDisappear:animated];
            popoverView=nil;
            [self.view removeFromSuperview];
            self.contentViewController = nil;
            self.titleText = nil;
            self.titleColor = nil;
            self.titleFont = nil;
        }

    }
}

当我尝试调用该方法时:

- (void) dismissPopoverAnimatd:(BOOL)animated

什么都没发生。 当我在popovertable中进行选择时,谁能指出我正确的方向,使该popOverView消失?

我认为问题是您在didSelectRowAtIndexPath方法中再次实例化了弹出框。 相反,您应该创建一个成员并使用它来关闭。 看到这个答案

我通过添加解决了它:

@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
{  
    TSPopoverController *popoverController;   
}

然后我在下面的函数中调用了它:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    ...

    [popoverController dismissPopoverAnimatd:YES];

}

感谢您为我指引正确的方向@xoail!

暂无
暂无

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

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