在 ios6 中展开故事板 segue 是否取代了使源场景实现委托以将数据从子场景传递回 ios5 中的父场景的需要?
我通常这样做的方式是:
Parent Controller Header: 调用子场景的Delegate
@interface ParentViewController : UIViewController <ChildViewControllerDelegate>
//ok not much to show here, mainly the delegate
//properties, methods etc
@end
Parent Controller Main(body): 准备segue,设置委托,从子场景创建返回方法
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"toChildScene"])
{
UINavigationController *childViewController = segue.destinationViewController;
childViewController.delegate = self;
}
}
#pragma mark - Delegate Segue Methods
-(void) childViewControllerDidSave: (ChildViewController *) controller Notes:(NSString *)sNotes
{
someTextLabel.Text = sNotes
[self dismissModalViewControllerAnimated:YES];
}
Child Controller Header: 创建委托,引用父场景方法
@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
Child Controller Main(body): 调用父场景方法
- (IBAction)someAction:(id)sender
{
[self.delegate childViewControllerDidSave:self sNotes:someTextField.text];
}
所以现在百万美元的问题: 这个过程现在在 iOS 6 中是否更简单?我可以使用展开转场/退出转场来减少很多工作吗?任何例子将不胜感激。