Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

geiger10d

macrumors member
Original poster
Jan 31, 2011
57
0
hey guys, in my app im making a weight tracker, so i made a picker view
it works fine, but when a picker is holding numbers, i need to know a way to have a picker componet hold numbers from like 0-1000 is there a way to do that? or do i actually have to put @"1",@"2"etc all the way up to 1000! please help!!

heres my code

Code:
- (void)viewDidLoad {
	
	NSArray *breadArray = [[NSArray alloc] initWithObjects:@"white", @"Whole Wheat", @"rye", @"SourDough", @"Seven Grain", nil];
	self.breadTypes = breadArray;
	[breadArray release];
	
	NSArray *fillingArray = [[NSArray alloc] initWithObjects:@"Ham", @"Turkey", @"Penut Butter", @"Tuna", @"Sevvv",@"adfadsf", @"asdasd", nil];
	self.fillingTypes = fillingArray;
	[fillingArray release];
	
	NSArray *weightArray = [[NSArray alloc] initWithObjects:@"LBS", @"KILO", nil];
	self.weightTypes = weightArray;
	[weightArray release];
	
	
    [super viewDidLoad];
}
 
Code:
int max =1000;
NSMutableArray *myArray = [NSMutableArray arrayWithCapacity:max];
int current = 1;
while(current<=max)
{
[myArray addObject:[[NSNumber numberWithInt:current] stringValue];
current++
}

Seems pretty simple?

p.s. I just typed this into the reply box: it's not tested etc
 
Code:
int max =1000;
NSMutableArray *myArray = [NSMutableArray arrayWithCapacity:max];
int current = 1;
while(current<=max)
{
[myArray addObject:[[NSNumber numberWithInt:current] stringValue];
current++
}

Seems pretty simple?

p.s. I just typed this into the reply box: it's not tested etc


why do i have to change it to a mutable array?
 
oh yes im sorry, but that code did not work, the last two lines of it i think were off starting with {

1) Learn how to report issues. Saying it "did not work" is about as useful as a chocolate fireguard. If it didn't compile what are the errors? On what line? If it did not do what was expected then what did it do? How did this differ from expectations

2) You should be able to fix it yourself.
 
easy...

Code:
	{
		[myArray addObject:[[NSNumber numberWithInt:current] stringValue];
		 current++
		 }

error i got was m:79: error: expected ']' before ';' on those lines.


if i knew how to fix it... i wouldnt be asking.. if you dont want to help me out then you dont have to reply.
 
easy...

Code:
	{
		[myArray addObject:[[NSNumber numberWithInt:current] stringValue];
		 current++
		 }

error i got was m:79: error: expected ']' before ';' on those lines.


if i knew how to fix it... i wouldnt be asking.. if you dont want to help me out then you dont have to reply.

Uh hu so you need to add a ] to balance out the [. There are three [ and only 2 ].
 
Uh hu so you need to add a ] to balance out the [. There are three [ and only 2 ].

Code:
int max =1000;
	NSMutableArray *myArray = [NSMutableArray arrayWithCapacity:max];
	int current = 1;
	while(current<=max)
	{
		[myArray addObject:[[NSNumber numberWithInt:current] stringValue]];
		 current++
	}

is that in the right spot? bcausae i get a error with the } and the end of it saying /er.m:81: error: expected ';' before '}' token
 
thanks for your help, i switched it around a little bit by using this code insted

Code:
NSMutableArray *array = [[NSMutableArray alloc] init];
for(int i = 0; i < 1001; i++){
    [array addObject:[NSString stringWithFormat:@"%d", i]];
}
self.numberArray = array;
[array release];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.