Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-08-2012, 10:41 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 4
starvingpilotcompany is on a distinguished road
Default UIPickerView with 2 columns (selected row issue)

I have a pickerview with 2 columns, populated with numbers for angle and velocity. I eventually get their intValues so I can do a simple calculation. However whenever I select say component 3 on the second column NSlog also prints me the value for component 3 on the first column regardless of what component is selected.

Code:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row  inComponent:(NSInteger)component
{
    
    NSString *angle =[list objectAtIndex:row];
    NSString *velocity = [velList objectAtIndex:row];
    //the angle and velocity had to be parsed to get rid of the ".kts" after the number etc..
    NSString *realAngle = [angle substringWithRange:NSMakeRange(0,2)];
    NSString *realVelocity = [velocity substringWithRange:NSMakeRange(0,2)];
    double intVel = [realVelocity intValue];
    double intAngle = [realAngle intValue];
    float radAngle = (intAngle * M_PI/180);
    float degAngle = sin(radAngle);
    
    if (component == 0)
    {
        
        NSLog(@"%f",intVel);
        NSLog(@"%f", degAngle);
        
    }
    else
    {
        NSLog(@"%f",intVel);
        NSLog(@"%f", degAngle);

}
}

Last edited by starvingpilotcompany; 02-08-2012 at 10:44 AM.
starvingpilotcompany is offline   Reply With Quote
Old 02-08-2012, 10:43 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Look at where/how you are using "component" in that code. Why would you expect the output to be any different?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 10:47 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 4
starvingpilotcompany is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Look at where/how you are using "component" in that code. Why would you expect the output to be any different?
To tell you truth, I had a feeling it was that part of the code. I just started writing obj. c so I am not too familiar with this method. How can I differentiate the output so I can have "row/component" and something else?
starvingpilotcompany is offline   Reply With Quote
Old 02-08-2012, 11:07 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

I can't say, because I don't know how your data is arranged. I will guess that if you are getting the data into the correct components in the first place, then that would be your clue.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 11:13 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 4
starvingpilotcompany is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
I can't say, because I don't know how your data is arranged. I will guess that if you are getting the data into the correct components in the first place, then that would be your clue.
Everything is working, in fact NSLog will log the proper info. In angles I have 10, 20, 30 and in the velocity, I have 1, 2, 3. When I select the angle of 20, it will Log, 20 and the velocity of 2 and if I leave the angle on 20 when I select 3 on the right side, it will log whatever 30 even though the 20 is selected.
starvingpilotcompany is offline   Reply With Quote
Old 02-08-2012, 11:27 AM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

This method is telling you what was touched. So it was row 5 in the second column, or whatever. It doesn't tell you anything about any other columns or rows. So if you need that information, you will have to interrogate the picker.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-08-2012, 11:32 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 4
starvingpilotcompany is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
This method is telling you what was touched. So it was row 5 in the second column, or whatever. It doesn't tell you anything about any other columns or rows. So if you need that information, you will have to interrogate the picker.
Gotcha, I will read a little more and figure out which method I need. Thanks for clearing that up.
starvingpilotcompany is offline   Reply With Quote
Old 02-08-2012, 11:56 AM   #8 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

Try to get the item in the selected row for your Component.

NSString *angle =[list objectAtIndex:[pickerView selectedRowInComponent:0]];
NSString *velocity = [velList objectAtIndex:[pickerView selectedRowInComponent:1]];
GHuebner is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 390
12 members and 378 guests
7twenty7, chiataytuday, fiftysixty, gmarro, iOS.Lover, KennyChong, kilobytedump, Leslie80, Matrix23, ryantcb, stanny, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:22 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0