我有一个情节提要,其中放置了所有viewControllers。我正在StoryboardID
用作:
AddNewPatientViewController * viewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"addNewPatientVC"];
[self presentViewController:viewController animated:YES completion:nil];
在AddNewPatientViewController
我添加的自定义init方法或构造函数中,您可以这样说:
-(id) initWithoutAppointment
{
self = [super init];
if (self) {
self.roomBedNumberField.hidden = true;
}
return self;
}
所以我的问题是使用呈现视图控制器哪能上述笏init
与这个自订init
我做了。
我已经尝试过将其替换为上面的代码,但是没有用。
AddNewPatientViewController *viewController = [[AddNewPatientViewController alloc] initWithoutAppointment];
[self presentViewController:viewController animated:YES completion:nil];
它不是用这种方法最好的主意。起初,我想建议您设置的实例后,该财产; 会更好
无论如何,如果您想创建这样的构造函数,则可以将其带有实例化的代码放置在其中,因此它看起来像
-(id) initWithoutAppointment
{
self = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"addNewPatientVC"];
if (self) {
self.roomBedNumberField.hidden = true;
}
return self;
}
但这不是一个好的代码
已编辑
可能是样式问题,但是我宁愿不要这样做,因为视图控制器不必了解UIStoryboard。如果要使用这种方法,最好将其移至其他工厂。如果我选择在没有Storyboard或带Storyboard的其他项目中使用此VC,但使用其他名称,它将容易出错。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句