假设我们有 2 个名为ViewControllerA 和ViewControllerB的视图控制器。
当我不使用情节提要时,我有以下初始化机制。
//ViewControllerA.h
@interface ViewControllerA : UIViewController
@end
//ViewControllerA.m
@implementation ViewControllerA
- (IBAction)showViewControllerB:(id)sender {
ViewControllerB *vcB = [[ViewControllerB alloc] initWithTitle:@"Test"];
[self.navigationController pushViewController:vcB animated:YES];
}
@end
//ViewControllerB.h
@interface ViewControllerB : UIViewController
- (id)initWithTitle:(NSString *)title;
@end
//ViewControllerB.m
@interface ViewControllerB()
@property (nonatomic, retain) NSString *title;//Private scope.
@end
@implementation ViewControllerB
- (id)initWithTitle:(NSString *)title {
self = [self init];
if(self)
{
_title = title;
}
return self;
}
@end
如何使用情节提要实现此目的而不在公共范围(ViewControllerB.h)中声明标题属性?
提前致谢。