ios - 展开 Storyboard(退出)segue 是否取代了父场景中对子代理的需求?
<p><p>在 ios6 中展开 Storyboard segue 是否取代了让源场景实现委托(delegate)以将数据从子场景传递回 ios5 中的父场景的需要?</p>
<p>我通常的做法是:</p>
<p><strong>父 Controllerheader :</strong>
<em>调用子场景的代理</em></p>
<pre><code>@interface ParentViewController : UIViewController <ChildViewControllerDelegate>
//ok not much to show here, mainly the delegate
//properties, methods etc
@end
</code></pre>
<p><strong>父 Controller 主体(主体):</strong>
<em>准备segue,设置委托(delegate),从子场景创建返回方法</em></p>
<pre><code>-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([ isEqualToString:@"toChildScene"])
{
UINavigationController *childViewController = segue.destinationViewController;
childViewController.delegate = self;
}
}
#pragma mark - Delegate Segue Methods
-(void) childViewControllerDidSave: (ChildViewController *) controller Notes:(NSString *)sNotes
{
someTextLabel.Text = sNotes
;
}
</code></pre>
<p><strong>子 Controller 标题:</strong>
<em>创建委托(delegate),引用父场景方法</em></p>
<pre><code>@class ChildViewController;
@protocol ChildViewControllerDelegate <NSObject>
-(void) childViewControllerDidSave: (ChildViewController *) controller Notes:(NSString *)sNotes
@end
@interface ChildViewController : UIViewController
@property (weak, nonatomic) id <ChildViewControllerDelegate> delegate;
//properties, methods, etc
@end
</code></pre>
<p><strong>子 Controller 主体(主体):</strong>
<em>调用父场景方法</em></p>
<pre><code>- (IBAction)someAction:(id)sender
{
;
}
</code></pre>
<p><strong>现在是百万美元的问题:</strong>
现在这个过程在 iOS 6 中更简单了吗?我可以使用展开转场/退出转场来减少很多工作吗?任何示例将不胜感激。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>是的。</p>
<p>展开转场是一种抽象的委托(delegate)形式。在 iOS 6 中,当关闭 ViewController 时,使用展开而不是委托(delegate)来向后传递数据更简单。</p>
<p>在父 ViewController 中,创建一个返回 <code>IBAction</code> 并将 <code>UIStoryboardSegue</code> 作为参数的展开方法:</p>
<pre><code>- (IBAction)dismissToParentViewController:(UIStoryboardSegue *)segue {
ChildViewController *childVC = segue.sourceViewController;
self.someTextLabel.Text = childVC.someTextField.text;
}
</code></pre>
<p>然后,在 subviewController 中,按住 Control 从您的关闭按钮拖动到绿色退出图标以连接展开转场:</p>
<p> <img src="/image/5o36p.png" alt="enter image description here"/> </p></p>
<p style="font-size: 20px;">关于ios - 展开 Storyboard(退出)segue 是否取代了父场景中对子代理的需求?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/13368480/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/13368480/
</a>
</p>
页:
[1]