【问题标题】:Getting a popOver from a popover for an ios application从 ios 应用程序的弹出窗口中获取弹出窗口
【发布时间】:2016-06-02 10:15:16
【问题描述】:

我的场景是这样的。 我有一个带有按钮的表格视图单元格。如果触发它,菜单将弹出如下所示

对于上面的菜单弹出窗口,源是出现在每个单元格最右边的按钮。

我有另一个名为 diplayAccounts 的表视图。 单击弹出菜单的单元格(即视图层次结构)时,displayAccounts 视图控制器需要显示为弹出框。我怀疑它的来源应该是什么。

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
menuTapped(self)
} 

方法menuTapped如下

func menuButtonTapped(sender: AnyObject)
{
    let storyboard : UIStoryboard = UIStoryboard(name: "Storyboard", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("HierarchyTableViewController") as! HierarchyTableViewController
    vc.modalPresentationStyle = UIModalPresentationStyle.Popover
    let popover: UIPopoverPresentationController = vc.popoverPresentationController!
    popover.sourceView = sender as? UIView
    popover.delegate = self
    presentViewController(vc, animated: true, completion:nil)
}

我遇到的错误

请帮帮我。

【问题讨论】:

  • "现在我想在点击 viewHierarchy 时获得另一个弹出窗口" 你这是什么意思?
  • 我有另一个名为 diplayAccounts 的表视图。单击弹出菜单的单元格(即视图层次结构)时,需要将 displayAccounts 视图控制器显示为弹出框。我怀疑它的来源应该是什么。

标签: ios uipopovercontroller


【解决方案1】:

在另一个弹出窗口中显示弹出窗口不是一个好主意(来自 Apple 移动人机界面指南)

你能做的最好的事情就是

在弹出视图控制器类中

  • 在视图控制器类中实现一个委托协议,以显示附件中所示的项目列表。
  • 在该委托协议中,添加一个带有参数的回调方法以包含所选单元格的详细信息。
  • 在弹出框类的视图控制器中添加委托属性。
  • 从单元格选择事件中调用委托方法。

在显示弹出框所在按钮的单元格类中

(即上图中显示44087和111的单元格)

  • 在弹出之前初始化委托对象
  • 实现委托协议中声明的委托方法以获取选择事件。
  • 显示您想要的另一个弹出窗口。

    更新

这将是弹出视图控制器,显示如上所示的项目列表

PopOverWithListItemsViewController.h 文件

#import <UIKit/UIKit.h>

@protocol PopoverWithListItemsViewDelegate <NSObject>

- (void)didSelectedListItemAtIndex:(NSInteger)index;

@end

@interface PopOverWithListItemsViewController : UIViewController

@property (nonatomic, weak) id<PopoverWithListItemsViewDelegate> delegate;

@end

在表格视图选择事件中,添加委托调用,如

NSInteger indexOfSelectedItem =  4;// jus for demo setting index as 4
[self.delegate didSelectedListItemAtIndex:indexOfSelectedItem];

在您展示列表弹出框的类中,添加以下内容

第一步

您呈现弹出窗口的类应如下所示向委托确认

@interface ViewController () &lt;PopoverWithListItemsViewDelegate&gt; // let ViewController is the class from which you presenting the pop over

第二步

// Let this be the cell's button tap event from which you presenting the pop over
- (IBAction)buttonTapEvent:(id)sender
{
  // Presenting pop over sections
  PopOverWithListItemsViewController *listItemsPopOverVC = [[PopOverWithListItemsViewController alloc] init];
  listItemsPopOverVC.delegate = self;
  // pop over presenting with listItemsPopOverVC as popover's view controller
}

第三步

// Delegate method implementation.
- (void)didSelectedListItemAtIndex:(NSInteger)index
{
  // Here we get the index of the selected cell in the popover.
  // Present the new popover from here, after customizing the new pop over contents.
}

【讨论】:

  • 在第三步中,您告诉我为下一个弹出框编写代码,但我在这里发现的困难是如何将按钮作为源代码放在这里。我没有正确的参考@Alex
  • 执行步骤 1,2, 3 的类将具有对按钮的出口引用,对吗?我认为应该是一些 UITableViewCell 类。
  • 是的,我们在 cellForRowAtIndexPath 中有它,但在 step-3 中, - (void)didSelectedListItemAtIndex:(NSInteger)index 方法我们没有它。
  • 你有一个自定义的单元格类,你使用你的 cellForRowAtIndexPath 来创建表格视图单元格吗?或者你在那里自定义 UITableViewCell?
猜你喜欢
  • 1970-01-01
  • 2011-09-30
  • 1970-01-01
  • 1970-01-01
  • 2018-05-10
  • 1970-01-01
  • 1970-01-01
  • 2022-12-14
  • 2021-01-08
相关资源
最近更新 更多