如何获得UISwitch的价值? [英] How to get the value of a UISwitch?

查看:95
本文介绍了如何获得UISwitch的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手的iOS程序员,我有一个问题。

I am a newbie iOS programmer and I have a problem.

我目前使用iOS Core Data,我的问题是,我想通过取一个 UISwitch 。

I currently work on iOS Core Data and my problem is that I want to insert data into a boolean attribute to a database by taking the value of a UISwitch.

问题是,我不知道它是什么方法我必须调用(例如.text做同样的事情,但对于UITextField)。我做了一个小的谷歌搜索,但没有结果。这里是一些代码:

The problem is that i don't know what it the method i have to call (e.g .text does the same thing but for UITextField). I have done a small google search but no results. Here is some code:

[newContact setValue:howMany.text forKey:@"quantity"]; 
[newContact setValue:important.??? forKey:@"important"]; 

howmany是一个文本字段,重要的是一个UISwitch

howmany is a textfield, important is a UISwitch

推荐答案

保存

[newContact setObject:[NSNumber numberWithBool:important.on] forKey:@"important"]; 

检索

BOOL on = [[newContact objectForKey:@"important"] boolValue];

这篇关于如何获得UISwitch的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆