gpt4 book ai didi

ios - 如何在 Objective C 中创建宏以在运行时执行多个模块?

转载 作者:行者123 更新时间:2023-11-29 04:33:25 25 4
gpt4 key购买 nike

在此源代码中是模块 FirstDetailViewController 的链接

FirstDetailViewController *newDetailViewController = [[FirstDetailViewController alloc] initWithNibName:@"FirstDetailView" bundle:nil];
detailViewController = newDetailViewController;

我想要一个字符串

module = [[NSString] alloc] initWithString:@"SecondDetailViewController"];

我想将字符串模块转换为代码以便在运行时更改

module *newDetailViewController = [[module alloc] initWithNibName:module bundle:nil];
detailViewController = newDetailViewController;

其中模块有多个名称

module = [[NSString] alloc] initWithString:@"ClientDetailViewController"];
…;
module = [[NSString] alloc] initWithString:@"FriendDetailViewController"];
…;
module = [[NSString] alloc] initWithString:@"FishDetailViewController"];
…;

如何使用变量模块来实现这个?

最佳答案

试试这个:

UIViewController* newDetailViewController = [[NSClassFromString(module) alloc] initWithNibName:module bundle:nil];

关于ios - 如何在 Objective C 中创建宏以在运行时执行多个模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11386068/

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