iphone - 使用 segues 获取对 UIPopoverController 的引用
<p><p>可以通过编程方式创建一个 UIPopoverController,然后设置它的 viewController、passthroughView 等:</p>
<pre><code>- (IBAction)showCustomPopoverButtonHandler:(id)sender {
if (self.colorPicker == nil) {
self.colorPicker = [ initWithStyle:UITableViewStylePlain];
_colorPicker.delegate = self;
self.colorPickerPopover = [ initWithContentViewController:_colorPicker];
}
];
[self.colorPickerPopover presentPopoverFromRect:self.showCustomPopoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}
</code></pre>
<p>但是,我想利用 Storyboard/序列。采用这种方法时,我看不到如何获取对 UIPopoverController 实例的编程引用:</p>
<p> <img src="/image/pIgv2.png" alt="enter image description here"/> </p>
<p>有人知道怎么做吗?我希望像</p>
<pre><code>UIPopoverController* pvc = self.popoverController;
</code></pre>
<p>我还列举了 childViewControllers 来检查它们的类类型:</p>
<pre><code> // Get references to child view controllers.
for(NSUInteger index = 0; index < self.childViewControllers.count; index++){
id obj = self.childViewControllers;
if(]){
self.menuPopoverController = self.childViewControllers;
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在苹果文档中找到答案:<a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIStoryboardPopoverSegue_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">UIStoryboardPopoverSegue Class Ref</a> </p>
<p>我在 prepareForSegue 中转换了 segue,并将 strong iVar 设置为 popoverController 属性,如下所示:</p>
<pre><code>-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if(){
// Typical delegate setup.....
UIStoryboardPopoverSegue* ps = (UIStoryboardPopoverSegue*)segue;
self.popoverController = ps.popoverController;
;
}
}
</code></pre>
<p>像魅力一样工作。</p>
<p>您也可以像这样使用它(以相同的方法)</p>
<pre><code>-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if(]){
self.menuPopoverController = ((UIStoryboardPopoverSegue*)segue).popoverController;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 使用 segues 获取对 UIPopoverController 的引用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15208114/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15208114/
</a>
</p>
页:
[1]