<分区>
如何在 WEpopover Controller 中包含 uibutton,我想要在 WEpopover 中设置一组 3 个按钮,单击导航到其他 View 。我应该在 WEpopover Controller 中更改哪里?
<分区>
如何在 WEpopover Controller 中包含 uibutton,我想要在 WEpopover 中设置一组 3 个按钮,单击导航到其他 View 。我应该在 WEpopover Controller 中更改哪里?
最佳答案
在引擎盖下,WEPopover 的工作方式是向 mainWindow
添加一个 subview ,一个“容器”,它是 UIView
的子类,它位于您的 View 层次[1]。它向该容器添加给定 View Controller 的 view
属性。要知道如何调整该 View 的大小,它会向 View Controller 询问其 contentSizeForViewInPopover
。
因此,设置 3 个按钮的方式与为任何其他 View Controller 设置 3 个按钮的方式相同。唯一的区别是,在处理 3 个按钮的 UIViewController
子类中,您需要设置 contentSizeForViewInPopover
。
您可以在init
或viewDidLoad
中设置此属性。 (请记住将其添加到正确的 init
方法中——例如,如果您在 Storyboard中制作此 View Controller ,则不会调用 init
而是调用 initWithCoder :
).
要实际添加按钮,您可能需要在 viewDidLoad
中使用如下代码:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[1] 如果您向一个 View 询问其父 View ,然后向该 View 询问其父 View ,依此类推,您最终将到达 mainWindow
。
关于iphone - Wepopover 控件中的 Uibutton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13339232/