 |
 |
|
 |
01-27-2009, 08:47 PM
|
#1 (permalink)
|
|
New Member
Join Date: Aug 2008
Posts: 23
|
Return value from picker that is not the label
Is it possible to return a value from a picker that isn't what it has as it's label? I would like to return the primary key of the value listed in my picker. The values are loaded from sqlite.
|
|
|
01-27-2009, 08:55 PM
|
#2 (permalink)
|
|
New Member
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
|
Look at it this way. You provided a picker view delegate that returned a title based on a row number and component number.
When the user picks a value you get notified with the same values - a component number and row number. Use the same logic to get your other data.
|
|
|
01-27-2009, 09:01 PM
|
#3 (permalink)
|
|
New Member
Join Date: Aug 2008
Posts: 23
|
Are you saying to just fake the primary key by using the row number and hope that it is the same as the actual primary key? What if the query is reordered, it won't line up at that point. Is there a way to get the primary key of the record without having to do a whole query to get that?
|
|
|
01-27-2009, 09:13 PM
|
#4 (permalink)
|
|
New Member
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
|
How did you get the data to begin with to populate the picker? I can't give too concrete of an answer because I don't know what you are doing. But in general I assume you are reading some data from a database to populate your pick view data model. Save enough info in that data model so that when a user picks a row from a component, you can grab enough data from the model to do whatever further query you need from the database.
|
|
|
01-27-2009, 09:24 PM
|
#5 (permalink)
|
|
New Member
Join Date: Aug 2008
Posts: 23
|
Before the query I create an array. After the query I do
Code:
NSString *NameField = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
[myArray addObject:NameField];
I don't understand how I would go about adding another value to my array. I come from a web background and understand multidimensional arrays but I do not know the syntax to create one in Cocoa. That's why I asked if there was a way to setup the view picker like a select box on the web -- the label being different from the value.
|
|
|
01-27-2009, 09:27 PM
|
#6 (permalink)
|
|
New Member
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
|
Two arrays would work or an array of dictionaries where each dictionary contains the label and key you need.
|
|
|
01-27-2009, 09:32 PM
|
#7 (permalink)
|
|
New Member
Join Date: Aug 2008
Posts: 23
|
Thanks, I didn't realize that you could do an array of dictionaries.
I didn't really know the proper question to ask and I appreciate the help.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 477 |
| 40 members and 437 guests |
| AdyCoder, alt-088, chakri_123, chaoz1337, crossfire, djp_phillips, dkaestli, ejw, Falcon80, Georg, hatembr, hello24, ideafactory, iphoneOpenGL, jamison, Johanovski, Jompe71, Juan_Garcia, Locker, miguel.campiao, mohan.agadkar, Mopedhead, myPhone, Nicolas R, nobre84, nycos, ovycom, pravin, preethaAjayan, raviram, sandman4sure, sayhong, sharhelia, stanny, stlau, Straathond, thadre, toughturtle, vinnilico, Zoid |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,356
Threads: 39,149
Posts: 171,628
Top Poster: smasher (2,577)
|
| Welcome to our newest member, Jakison |
|