Objective C Question

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Objective C Question

Post by ibly31 »

I doubt anyone here knows, but its worth a try. I'm making a swimming time converter app for my ipod touch. I have a picker view and I need to have event:minutes:seconds:hundredths as the pickers rows. The events I have already created an NSArray for, but I really don't feel like writing out

Code: Select all

NSArray *eventTypes = [[NSArray alloc] initWithObjects:@"00",@"01",@"02" etc...];
Is there a way to do it like this:

Code: Select all

NSLog(@"I'm used to C++")

NSArray *eventMinutes = [[NSArray alloc] init];

for x 1 through 60
{
nsarray[x] = x;
}

Please help!
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Innerscope
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon May 04, 2009 5:15 pm
Current Project: Gridbug
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: Obj-C, C++
Location: Emeryville, CA
Contact:

Re: Objective C Question

Post by Innerscope »

I'd try to help you, but I'm not even sure what you're trying to accomplish. Why do you use an array if you just want a counter?
Look at this site, hopefully it will help: http://www.otierney.net/objective-c.html
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: Objective C Question

Post by ibly31 »

To use a picker view, The little dial, you need to specify the NSArray to use for the objects in it. Its kinda like the drop down lists in web pages, except instead of using easy tags inside the bigger drop down list tag, I have to specify an array. I'm not familiar with ObjC so that is why I am asking.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Innerscope
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon May 04, 2009 5:15 pm
Current Project: Gridbug
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: Obj-C, C++
Location: Emeryville, CA
Contact:

Re: Objective C Question

Post by Innerscope »

ibly31 wrote:To use a picker view, The little dial, you need to specify the NSArray to use for the objects in it. Its kinda like the drop down lists in web pages, except instead of using easy tags inside the bigger drop down list tag, I have to specify an array. I'm not familiar with ObjC so that is why I am asking.
Ok, I guess a more appropriate question would be, why use a UIPickerView? Couldn't you just use a UILabel with an NSTimer?
I guess I'm really confused by the what you mean by "swimming time converter". :|
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: Objective C Question

Post by ibly31 »

What I want the user to do is to put in their time, change the settings(Long course meters, short course meters,yards) and convert their time from meters to yards or vice versa. The Pickerview would come up with something like this:
___________________________
| 200 Breast | 00 | 00 | 00 |
| 100 Butter | 00 | 00 | 00 |
| 200 Butter | 00 | 00 | 00 |
| 300 Breast | 00 | 00 | 00 |
===========================
Event type Min Sec Hundredths
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Innerscope
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon May 04, 2009 5:15 pm
Current Project: Gridbug
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: Obj-C, C++
Location: Emeryville, CA
Contact:

Re: Objective C Question

Post by Innerscope »

ibly31 wrote:What I want the user to do is to put in their time, change the settings(Long course meters, short course meters,yards) and convert their time from meters to yards or vice versa. The Pickerview would come up with something like this:
___________________________
| 200 Breast | 00 | 00 | 00 |
| 100 Butter | 00 | 00 | 00 |
| 200 Butter | 00 | 00 | 00 |
| 300 Breast | 00 | 00 | 00 |
===========================
Event type Min Sec Hundredths
hmm, ok. So you want the user to enter a time then select meters/yards, then convert that number accordingly?
Would this work?: http://img.photobucket.com/albums/v323/ ... UIPict.png
That would be easier to implement IMO.

I can kinda see why you want to use the UIPickerView, but from what I read on it, I feel like it's making things more complex then they have to be.
If you're stuck on using it though, I can't really help you cause I've never used one. Looking at the reference should help you figure it out though:
http://developer.apple.com/iphone/libra ... rView.html
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: Objective C Question

Post by ibly31 »

Well the different amount of meters/yards would make the conversions different, so a 200 breast and a 100 breast are very different. Also the problem isnt the UIPickerView, its the NSArray. I would just like to know how to add objects to an NSArray through a loop.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Innerscope
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon May 04, 2009 5:15 pm
Current Project: Gridbug
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: Obj-C, C++
Location: Emeryville, CA
Contact:

Re: Objective C Question

Post by Innerscope »

ibly31 wrote:Well the different amount of meters/yards would make the conversions different, so a 200 breast and a 100 breast are very different. Also the problem isnt the UIPickerView, its the NSArray. I would just like to know how to add objects to an NSArray through a loop.
Alright, I still feel like this is more complicated than it needs to be (my example as well), but we'll roll with it. ;)

NSArray's AFAIK are static. Meaning, they can't be re-sized dynamically. However, you can initialize an NSArray with a C array, using the initWithObjects method. (check out the documentation for more info: http://developer.apple.com/iphone/libra ... tm/NSArray )

You could also try to use an NSMutableArray (array capable of mutating= dynamic re-sizing):

Code: Select all

	NSMutableArray *eventMinutes = [[NSMutableArray alloc] init];
	int x;
	NSNumber *min;
	NSString *readableMin;
	for(x=1; x< 61; x++){
		min = [NSNumber numberWithInt:x];
		readableMin = [min stringValue];
		[eventMinutes addObject:readableMin];
	}
There are probably more optimized ways of going about what I did. That was kinda quick and dirty, but I hope that helps. Also remember that "research assistant" (help>research assistant) is you're best friend in Xcode. :)
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
Post Reply