Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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 如何在不使用InterfaceBuilder的情况下将UISwitch(切换开关)添加到UIToolBar_Iphone_Cocoa Touch_Uitoolbar_Uiswitch - Fatal编程技术网

Iphone 如何在不使用InterfaceBuilder的情况下将UISwitch(切换开关)添加到UIToolBar

Iphone 如何在不使用InterfaceBuilder的情况下将UISwitch(切换开关)添加到UIToolBar,iphone,cocoa-touch,uitoolbar,uiswitch,Iphone,Cocoa Touch,Uitoolbar,Uiswitch,如何在不使用InterfaceBuilder的情况下将UISwitch(切换开关)添加到UIToolBar? 它不是系统项,因此我无法使用 UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh

如何在不使用InterfaceBuilder的情况下将UISwitch(切换开关)添加到UIToolBar? 它不是系统项,因此我无法使用

UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                                             target:self
                                                                             action:@selector(pressButton1:)];
如何以相同的方式添加切换开关?

多谢各位

只需将开关用作自定义视图。

只需将开关用作自定义视图。

以下是我在swift应用程序中所做的操作,我必须在两种不同的显示模式之间切换

    let optionSwitch:UISwitch = UISwitch()

    let optionToolButton:UIBarButtonItem = UIBarButtonItem(customView: optionSwitch);
    self.navigationItem.rightBarButtonItem = optionToolButton

下面是我在swift应用程序中所做的,我必须在两种不同的显示模式之间切换

    let optionSwitch:UISwitch = UISwitch()

    let optionToolButton:UIBarButtonItem = UIBarButtonItem(customView: optionSwitch);
    self.navigationItem.rightBarButtonItem = optionToolButton

但是,我无法将其设置为用户启用。我应该添加代码以便在触摸时切换吗?@srikanth:我想是的。条形按钮项目本身的视图也是一个按钮,可能会劫持触摸。不过,您可以设置条形按钮项的
目标
操作
属性。很抱歉,我学习缓慢。但是,我看到了下面的方法。它没有像其他方法那样的目标和行动。-(id)initWithCustomView:(UIView*)customView;对不起,我没有检查好。它正在切换。它正在工作。我需要为on和off条件添加选择器。谢谢。@srikanthrongali您是否尝试绑定到
UIControlEventsValueChanged
?但是,我无法将其设置为用户启用。我应该添加代码以便在触摸时切换吗?@srikanth:我想是的。条形按钮项目本身的视图也是一个按钮,可能会劫持触摸。不过,您可以设置条形按钮项的
目标
操作
属性。很抱歉,我学习缓慢。但是,我看到了下面的方法。它没有像其他方法那样的目标和行动。-(id)initWithCustomView:(UIView*)customView;对不起,我没有检查好。它正在切换。它正在工作。我需要为on和off条件添加选择器。谢谢。@srikanthrongali您是否尝试绑定到
uicontrolEventsValue Changed