gpt4 book ai didi

ios - 无法传递 UIVewController 的实例 - iOS

转载 作者:行者123 更新时间:2023-12-01 17:50:52 26 4
gpt4 key购买 nike

我有一个带有我制作的方法的应用程序,想法是这个方法将打开我想要的任何 View Controller 。我做到了,所以我必须拥有许多相同代码的副本。但是,它不起作用,Xcode 不断出现错误:

Invalid operands to binary expression (UIViewController ) and 'unsigned long()(const char*)')



这是我的方法:
-(void)open_view_controller:(UIViewController *)controller_name :(NSString *)view_name {

controller_name *screen = [[controller_name alloc] initWithNibName:view_name bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:screen animated:YES completion:nil];
}

我只是想避免这样做:
CallCreator *screen = [[CallCreator alloc] initWithNibName:@"CallCreator" bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:screen animated:YES completion:nil];

我能做些什么来解决这个错误?我不明白出了什么问题,我传入了正确的类型 - UIViewController .

谢谢你的时间,丹。

最佳答案

您应该使用 Class而不是 UIViewController *

- (void)presentViewControllerOfClass:(Class)controllerClass viewName:(NSString *)viewName;
{
UIViewController *screen = [[controllerClass alloc] initWithNibName:viewName bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:screen animated:YES completion:nil];
}

这将像
[self presentViewControllerOfClass:MyViewController.class viewName:@"MyViewController"];

关于ios - 无法传递 UIVewController 的实例 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31692610/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com