从数组中取出未定义数量的 ViewController

发布于 2024-12-27 05:11:07 字数 952 浏览 2 评论 0原文

在我的应用程序中,我将 UIViewController 从 .plist 加载到数组中,然后,我需要取出这些 VC。问题是,由于 VC 的数量并不总是相同,所以我不知道每次我能抽出多少个。所以我正在寻找更好的工程解决方案 - 更好的迭代,而不是硬编码。

例如:

NSMutableArray *views = [[NSMutableArray alloc] init];

for (int i = [currentList count]; i > 0; i--) {
    UIViewController *view = [[UIViewController alloc] init];
    view.title = [NSString stringWithFormat:@"dgdg - %i", i];
    [views addObject:view];
}

所以这是我的 VC 数组,现在:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:**help** nil];

我尝试过:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:[views copy], nil];

和:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:[NSIndexSet..., nil];

我尝试过:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:[views objectAtIndex:0]... nil];

但都不起作用。提前致谢。

In my app, I load UIViewController into an array from a .plist, and then, I need to get those VC's out. The problem is, since the number of VC's is not always the same, then I don't know how many I'm getting out each time. So I'm looking for a better engeneered solution - better iteration, rather than hard coding.

For example:

NSMutableArray *views = [[NSMutableArray alloc] init];

for (int i = [currentList count]; i > 0; i--) {
    UIViewController *view = [[UIViewController alloc] init];
    view.title = [NSString stringWithFormat:@"dgdg - %i", i];
    [views addObject:view];
}

So there is my array of VC's, and now:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:**help** nil];

I tried:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:[views copy], nil];

and:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:[NSIndexSet..., nil];

I tried:

   myIvar = [[CustomSubClass alloc] initWithViewControllers:[views objectAtIndex:0]... nil];

but none of it worked. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2025-01-03 05:11:07

你想要的语法是这样的:

[[CustomSubClass alloc] initWithViewControllers:[views objectAtIndex:0], [views objectAtIndex:1], [views objectAtIndex:2], nil];

基本上只是重复所有参数用逗号分隔,然后总是让最终参数为零。

The syntax you want is like this:

[[CustomSubClass alloc] initWithViewControllers:[views objectAtIndex:0], [views objectAtIndex:1], [views objectAtIndex:2], nil];

Basically just repeat have all your arguments separated by commas, then always have the final argument be nil.

抱着落日 2025-01-03 05:11:07

视图是一个数组,您可以直接将其作为参数传递,如下所示:

 myIvar = [[CustomSubClass alloc] initWithViewControllers:views];

views is an array and you can pass this directly as a parameter like so:

 myIvar = [[CustomSubClass alloc] initWithViewControllers:views];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文