关闭 Popover 后更新第一个视图 [英] Update the first view after dismissing Popover

查看:23
本文介绍了关闭 Popover 后更新第一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从第一个视图控制器(tableview)转到第二个视图控制器,它是一个 tableview.在我不使用第二个视图之后,我需要在第一个控制器中重新加载表视图.如果我在弹出框外点击 popoverPresentationControllerDidDismissPopover 会被调用,但是如果第二个 tableview 中有另一个按钮返回到第一个,该怎么办?通常我需要用户点击添加按钮从表格视图中出来,而不是点击弹出窗口之外.我保留外部水龙头作为取消操作.

I segue from the first view controller(tableview) to the second view controller which is a tableview. After I am dont with the second view, I need to reload table view in the first controller. popoverPresentationControllerDidDismissPopover gets called if I tap outside the popover but what if there is another button in the second tableview which segues back to the first one? Normally I need user to tap Add button to come out of tableview rather than tapping outside the popover. I reserve the outside tap as the cancel action.

谢谢

推荐答案

以编程方式关闭委托方法 popoverPresentationControllerDidDismissPopover 时不会调用它.

The delegate method popoverPresentationControllerDidDismissPopover does not get called when you dismiss it programmatically.

解决方案是,当您通过调用 dismiss(animated:completion:) 关闭弹出框时,您也必须调用表视图来重新加载数据.

The solution is when you dismiss the popover by calling dismiss(animated:completion:), you have to call the table view to reload data too.

所以基本上你调用 tableView.reloadData() 两次.一个在 popoverPresentationControllerDidDismissPopover 中,一个在 dismiss(animated:completion:) 之后,它在你的添加按钮点击方法中.

So basically you call tableView.reloadData() twice. One in the popoverPresentationControllerDidDismissPopover, one after dismiss(animated:completion:) which is in your add button tapped method.

更新

从你的截图来看,我假设你的第一个视图控制器 (VC1) 是背景控制器,第二个视图控制器 (VC2) 是弹出窗口.

From you screenshot, I assume your first view controller (VC1) is the one on background, the second view controller (VC2) is the pop over.

如果是这样,您有两个选择:

If so, you have two options:

  1. 在 VC2 上,声明一个自定义协议来通知 VC1 重新加载表选择行并将委托在VC1到VC2中设置委托时查看数据.
  2. 您可以在 VC2 中简单地声明一个块属性,而不是使用协议.例如:

  1. On VC2, declare a custom protocol to notify VC1 to reload table view data whenever a row is selected and set delegate in VC1 to VC2.
  2. Instead of using a protocol, you can simply declared a block property in VC2. For example:

@property (copy, nonatomic) void (^itemSelectedHandler)();

当一个项目被选中时调用这个(仍在 VC2 中):

And when an item is selected call this (still in VC2):

self.itemSelectedHandler();

然后在 VC1 中,在初始化 VC2(即 popover)之后,您处理该块.例如:

Then in VC1, after initialising VC2, which is the popover, you handle the block. For example:

vc2.itemSelectedHandler = ^{
    [vc1.tableView reloadData];
}

不幸的是,我对 swift 编程没有经验,所以我必须使用客观的 c 代码作为示例.

Unfortunately, I'm not experienced with swift programming so I have to use objective c code as an example.

这篇关于关闭 Popover 后更新第一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆