简体   繁体   English

将UISwitch状态从一个View Controller传递到另一个ViewController

[英]Pass UISwitch State from One View Controller to Another ViewController

I have a UISwith in a viewcontroller A. I want to pass the state of the UISwitch to viewcontroller B. I am using Objective C. This is the code I'm using in viewcontroller A: 我在视图控制器A中有一个UISwith。我想将UISwitch的状态传递给视图控制器B。我正在使用ObjectiveC。这是我在视图控制器A中使用的代码:

if (![switchview isOn]) {
                NSLog(@"OFF");   
            } else {
                NSLog(@"ON");
                [comment setObject:@"YES" forKey:kESActivityPrivateKey];
            }

I need to save the value of the UISwitch in viewcontroller B. 我需要将UISwitch的值保存在viewcontroller B中。

Any help is appreciated. 任何帮助表示赞赏。

Don't try to access another view controller's view hierarchy directly. 不要尝试直接访问另一个视图控制器的视图层次结构。 You should treat another view controllers views (and a switch is a kind of view) as private. 您应该将另一个视图控制器视图(而开关是一种视图)视为私有视图。

Set an IBAction on your switch that points to the owning view controller. 在您的交换机上设置一个IBAction,该IBAction指向拥有的视图控制器。 In that action save the sate of the switch to a property of your view controller. 在该操作中,将开关的状态保存到视图控制器的属性。

You can then access the property from the other view controller. 然后,您可以从另一个视图控制器访问该属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将NSMutableDictionary从一个viewController传递到另一个View控制器? - How to pass NSMutableDictionary from one viewController to another View controller? 将nsmutablearray从一个ViewController传递到另一个View Controller - Pass nsmutablearray from one viewcontroller to another view controller 将数据从一个视图控制器传递到同一视图上的另一个视图控制器 - Pass data to from one viewcontroller to another viewcontroller on the same view 如何从 SWIFT 3 中的另一个 ViewController 检查 UISwitch 的状态? - How to check the state of an UISwitch from another ViewController in SWIFT 3? 从一个viewController调用另一个视图控制器的IBAction - Call IBAction of another view controller from one viewController 将NSManagedObject从一个视图控制器传递到另一个视图控制器 - Pass NSManagedObject from one view controller to another 无法将值从一个View Controller传递到另一个View Controller - Not able to pass value from one View Controller to another View Controller 从子级Viewcontroller(Tab)传递到视图控制器 - Pass from a child Viewcontroller (Tab) to a view controller 如何将soap对象传递给一个viewcontroller到Swift-3中的另一个视图控制器 - how can i pass soap object to one viewcontroller to another view controller in Swift-3 如何以编程方式从一个情节提要中的一个视图控制器转到另一个情节提要中的另一个视图控制器? - How to go from one view controller in One storyboard to another viewcontroller in another storyboard programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM