Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOutletUIViewController的集合_Iphone_Ios_Cocoa Touch_Uiviewcontroller_Interface Builder - Fatal编程技术网

Iphone iOutletUIViewController的集合

Iphone iOutletUIViewController的集合,iphone,ios,cocoa-touch,uiviewcontroller,interface-builder,Iphone,Ios,Cocoa Touch,Uiviewcontroller,Interface Builder,我想做一些类似于UITabBarController的事情UITabBarController具有属性viewControllers,我可以在其中添加IB中UIViewController*的实例。我正试图用我自己的VC做同样的思考: @property (nonatomic, copy) IBOutletCollection(UIViewController) NSArray *viewControllers; 但这不起作用。这对我们来说可能吗 编辑1。 Ramshad发布了正确的样本,但使

我想做一些类似于
UITabBarController
的事情
UITabBarController
具有属性
viewControllers
,我可以在其中添加IB中
UIViewController*
的实例。我正试图用我自己的VC做同样的思考:

@property (nonatomic, copy) IBOutletCollection(UIViewController) NSArray *viewControllers;
但这不起作用。这对我们来说可能吗

编辑1。

Ramshad发布了正确的样本,但使用了XIB。我想用故事板来实现它

编辑2在赏金价值的末尾…

我质疑瓦德克瓦恩的帖子,因为在
UITabBarController
的情况下,它可以工作。正如Ramshad所发布的,在NIBs中也是可能的。到目前为止,dasblinkenlight的帖子是最正确的,但没有回答这个问题。我把这个问题开着,因为我们会发现它是否对我们有限制,或者是什么方法


PS:为什么这些否决?

插座收集解决方案不起作用的原因是视图控制器不是插座。从:

插座是用符号IBOutlet和进行注释的属性 可以在nib文件或故事板中以图形方式设置其值

视图控制器不是图形对象

如果要使用IBMoutletCollection,则应仅使用一个视图控制器,并将视图放入集合中

但是,如果您希望每个视图都有一个控制器,则需要采用更为编程的方法。带有视图控制器的阵列可能是一个好的开始,但我不能说,因为我不知道您想用它们做什么

编辑:

@property (strong, nonatomic) IBOutletCollection(UIViewController) NSArray *ViewCollection;

//dismissing the earlier populated view
- (IBAction)dismiss:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}


//presenting the corresponding view.
- (IBAction)resetAction:(id)sender {      

    UISegmentedControl *mySegment = (UISegmentedControl *)sender;

    int index = 0;          
    for (UIViewController *viewItem in _ViewCollection) {

        if (index == mySegment.selectedSegmentIndex) {

            [self presentViewController:viewItem animated:YES completion:nil];
        }
        index++;
    }
}
更清楚地说,你似乎不明白我的意思:

不,这不一定是一种方式。故事板不是API,它是用于绘制场景和片段的图形工具。它是专门为基于标签栏的应用程序设计的

如果右键单击情节提要文件并选择“打开为”->“源代码”,您将看到选项卡栏控制器具有其他视图控制器所没有的特殊元素。在故事板文件中乱用XML是我无法理解的

如果要使用Nib文件,请使用Ramshads answer

如果你想尽可能接近故事板,请使用DasbLinkedLights回答


但你的问题的答案(据我所知)是否定的,没有办法通过故事板来实现这一点。如果是,它将被记录,而不是。

插座收集解决方案不起作用的原因是视图控制器不是插座。从:

插座是用符号IBOutlet和进行注释的属性 可以在nib文件或故事板中以图形方式设置其值

视图控制器不是图形对象

如果要使用IBMoutletCollection,则应仅使用一个视图控制器,并将视图放入集合中

但是,如果您希望每个视图都有一个控制器,则需要采用更为编程的方法。带有视图控制器的阵列可能是一个好的开始,但我不能说,因为我不知道您想用它们做什么

编辑:

@property (strong, nonatomic) IBOutletCollection(UIViewController) NSArray *ViewCollection;

//dismissing the earlier populated view
- (IBAction)dismiss:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}


//presenting the corresponding view.
- (IBAction)resetAction:(id)sender {      

    UISegmentedControl *mySegment = (UISegmentedControl *)sender;

    int index = 0;          
    for (UIViewController *viewItem in _ViewCollection) {

        if (index == mySegment.selectedSegmentIndex) {

            [self presentViewController:viewItem animated:YES completion:nil];
        }
        index++;
    }
}
更清楚地说,你似乎不明白我的意思:

不,这不一定是一种方式。故事板不是API,它是用于绘制场景和片段的图形工具。它是专门为基于标签栏的应用程序设计的

如果右键单击情节提要文件并选择“打开为”->“源代码”,您将看到选项卡栏控制器具有其他视图控制器所没有的特殊元素。在故事板文件中乱用XML是我无法理解的

如果要使用Nib文件,请使用Ramshads answer

如果你想尽可能接近故事板,请使用DasbLinkedLights回答


但你的问题的答案(据我所知)是否定的,没有办法通过故事板来实现这一点。如果是,它会被记录下来,而不是。

我已经使用
UISegmentedControl+iOutletCollection+presentViewController完成了您的要求

您可以根据需要使用任何控件,而不是
UISegmentedControl

我在
中添加了3个不同的
UIViewController1,2,3。

我还添加了两个额外的方法。一个用于显示相应的视图,另一个用于取消先前填充的视图

我已附上下面的设置屏幕截图

您只能使用一个UIViewController,而不是3个,并将其与一些逻辑一起重用:)

方法如下:

@property (strong, nonatomic) IBOutletCollection(UIViewController) NSArray *ViewCollection;

//dismissing the earlier populated view
- (IBAction)dismiss:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}


//presenting the corresponding view.
- (IBAction)resetAction:(id)sender {      

    UISegmentedControl *mySegment = (UISegmentedControl *)sender;

    int index = 0;          
    for (UIViewController *viewItem in _ViewCollection) {

        if (index == mySegment.selectedSegmentIndex) {

            [self presentViewController:viewItem animated:YES completion:nil];
        }
        index++;
    }
}
您可以从下载我的示例应用程序

Xib设置屏幕截图


我已经使用
UISegmentedControl+iOutletCollection+presentViewController完成了您的要求

您可以根据需要使用任何控件,而不是
UISegmentedControl

我在
中添加了3个不同的
UIViewController1,2,3。

我还添加了两个额外的方法。一个用于显示相应的视图,另一个用于取消先前填充的视图

我已附上下面的设置屏幕截图

您只能使用一个UIViewController,而不是3个,并将其与一些逻辑一起重用:)

方法如下:

@property (strong, nonatomic) IBOutletCollection(UIViewController) NSArray *ViewCollection;

//dismissing the earlier populated view
- (IBAction)dismiss:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}


//presenting the corresponding view.
- (IBAction)resetAction:(id)sender {      

    UISegmentedControl *mySegment = (UISegmentedControl *)sender;

    int index = 0;          
    for (UIViewController *viewItem in _ViewCollection) {

        if (index == mySegment.selectedSegmentIndex) {

            [self presentViewController:viewItem animated:YES completion:nil];
        }
        index++;
    }
}
您可以从下载我的示例应用程序

Xib设置屏幕截图


尽管看起来您无法将
UIViewController
s连接到
IBOutletCollection
s(或者有太多的人