从数组中取出未定义数量的 ViewController
在我的应用程序中,我将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要的语法是这样的:
基本上只是重复所有参数用逗号分隔,然后总是让最终参数为零。
The syntax you want is like this:
Basically just repeat have all your arguments separated by commas, then always have the final argument be nil.
视图是一个数组,您可以直接将其作为参数传递,如下所示:
views is an array and you can pass this directly as a parameter like so: