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-04-2012, 05:40 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 14
iph_s is on a distinguished road
Default UIPickerView values

I want UIPicker to start from 2 (0, 1 to be not displayed)
Code:
self.tmpArray = [NSMutableArray arrayWithCapacity:10];

    for(int x = 2; x < 10; x++)
    {
        [self.tmpArray addObject:[NSNumber numberWithInt:x]];
    }

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

    return [self.tmpArray count];
}
With the code above UIPicker shows 0,1,2,3 etc...
iph_s is offline   Reply With Quote
Old 02-04-2012, 07:28 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

Are you loading the values for the pickerView in the pickerView delegate?

Code:
#pragma mark - 
#pragma mark Picker Delegate Methods

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [self.tmpArray objectAtIndex:row];
}

Last edited by GHuebner; 02-04-2012 at 07:44 AM.
GHuebner is offline   Reply With Quote
Old 02-04-2012, 07:54 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 14
iph_s is on a distinguished road
Default

Here is the delegate I use:

Code:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSString *title;
    title = [@"" stringByAppendingFormat:@"%d",row];
    
    return title;
}
I tried your suggest but I get:

Code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x6a64b30'
iph_s is offline   Reply With Quote
Old 02-04-2012, 08:33 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

It looks like your delegate is just putting the number of the row as the title. So, it will put the 0 and 1 in the picker.

You need to fill with the objects in your array.

Quote:
Originally Posted by iph_s View Post
Here is the delegate I use:

Code:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSString *title;
    title = [@"" stringByAppendingFormat:@"%d",row];
    
    return title;
}
I tried your suggest but I get:

Code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x6a64b30'
GHuebner is offline   Reply With Quote
Old 02-04-2012, 10:41 AM   #5 (permalink)
Registered Member
 
Join Date: Jan 2012
Location: Illinois
Posts: 44
GHuebner is on a distinguished road
Default

Sorry, my fault. (I am still learning as well) I didnt realize it was a NSNumber in the array and not a NSString. Try this code instead.

Code:
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{

    NSString *title = [NSString stringWithFormat:@"%@", [self.tmpArray objectAtIndex:row]];
    return title;
    
}
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: 398
18 members and 380 guests
Apptronics RBC, Atatator, chiataytuday, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, kukat, LunarMoon, MAMN84, n00b, pbart, reficul, Retouchable, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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