如何从数据库sqlite向uipickerview添加值?
我是 sqlite 和编程新手, 我已经尝试了一周,但无法向前推进一点。我已经看到你帮助了很多人,我想你可以解决我的问题。我已经发布了很多,但我没有从任何地方得到任何回复这 。 你可以联系我: [email protected]
首先我必须创建两个在同一视图上单独的 uipickerviews。在该 pickerview 中,我必须从 sqlite 数据库表中插入值。 在第一个视图中,我必须从 sqlite 的第一个表中获取值。在第二个视图中,我必须通过与 id 进行比较来从第二个表中获取值。 视图必须位于同一视图上。
Table1:资格
CREATE TABLE 资格(id INTEGER PRIMARY KEY,名称 VARCHAR(50),描述 TEXT);
INSERT INTO "资格" VALUES(1,'PG','毕业后');
INSERT INTO "资格" VALUES(1,'学位','正在毕业');
INSERT INTO "资格" VALUES(1,'十+二','大学');
表2:课程
CREATE TABLE 课程 (Id Integer PrimaryKey,number Integer,name1 varchar(20),description1 Text(30));
INSERT INTO "课程" VALUES(1,1,'MCA','计算机硕士'); INSERT INTO“课程”VALUES(2,1,'MBA','商业硕士'); INSERT INTO "课程" VALUES(3,2,'BSc','科学学士'); INSERT INTO "课程" VALUES(4,2,'BCom','会计学学士'); INSERT INTO“课程”VALUES(5,3,'MPC','数学'); INSERT INTO“课程”VALUES(5,3,'BPC','生物学');
请参阅第一个表,我将得到值 PG,Degree,Ten+ 两个
当我单击 PG 时,它必须显示在文本字段中,在第二个选择器视图中我必须仅获取与 资格的“id” 当然是“数”。
当我们选择值时,它必须显示在文本字段中 感谢你
Am new to sqlite and also programming,
Am trying this from a week and not able to move a bit forward.I have seen U have helped many and I think I can be solved my problem by you.I have posted a lot,but I didnt get any reply from any where for this .
U can contact me : [email protected]
At first I have to create two separate uipickerviews on same view.In that pickerview I have to insert values from sqlite database tables.
In first view i have to get the values from first table of sqlite.And in second view i have to get the values from second table by comparing with the id.
the views must be on same view.
Table1:qualification
CREATE TABLE qualification ( id INTEGER PRIMARY KEY, name VARCHAR(50), description TEXT);
INSERT INTO "qualification" VALUES(1,'P.G','Post Graduation');
INSERT INTO "qualification" VALUES(1,'Degree','Under Graduation');
INSERT INTO "qualification" VALUES(1,'Ten+Two','college');
Table2:course
CREATE TABLE Course (Id Integer primarykey,number integer,name1 varchar(20),description1 Text(30));
INSERT INTO "Course" VALUES(1,1,'MCA','Master in computers');
INSERT INTO "Course" VALUES(2,1,'MBA','Master in Bussiness');
INSERT INTO "Course" VALUES(3,2,'BSc','Bachelor in sscience');
INSERT INTO "Course" VALUES(4,2,'BCom','Bachelor in accounts');
INSERT INTO "Course" VALUES(5,3,'MPC','Mathematics');
INSERT INTO "Course" VALUES(5,3,'BPC','Biology');
See in first table i will get values P.G,Degree,Ten+
Two
when i click on P.G it must display in textfield and in second pickerview I must get values only which matches with
"id" of qualification with
"number " of course.
And when we select value it must display in textfield
Thank u
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了一个项目来向您展示如何做您所要求的事情。
您可以从这里下载该项目:
http://www.crowsoft.com.ar/downloads /twoPickerViews.zip
可以在这里找到 iPhone 中 sqlite 的非常好的教程:
http://www.icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list -using-sqlite-part-1/
要管理 PickerView,您需要一个数组来保存数据。
我声明了两个类(资格和课程)来表示您的表和两个 NSMutableArray 变量来保存数据。
要链接两个 PickerView,您需要在视图控制器中实现 UIPickerViewDataSource 和 UIPickerViewDelegate:
要在用户选择资格时做出响应,您需要编写 didSelectRow:
您需要编写另外三个方法,numberOfComponentsInPickerView、numberOfRowsInComponent、titleForRow:
I have made a project to show you how to do what you are asking for.
You can download the project from here:
http://www.crowsoft.com.ar/downloads/twoPickerViews.zip
A very good tutorial for sqlite in iPhone could be found here:
http://www.icodeblog.com/2008/08/19/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-1/
To manage a PickerView you need an array to hold the data.
I have declared two classes (Qualification and Course) to represent your tables and two NSMutableArray variables to hold the data.
To link the two PickerViews you need to implement UIPickerViewDataSource and UIPickerViewDelegate in your view controler:
to respond when the user select a qualification you need to code didSelectRow:
You need to code three more methods, numberOfComponentsInPickerView, numberOfRowsInComponent, titleForRow: