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

textual

macrumors newbie
Original poster
Aug 24, 2008
6
0
i have a series of things...1 to n
i want to use a nav bar to scroll through them using the left and right buttons

first step is to dynamically set the title of the toolbar to say 'thing 1', 'thing 2'
i can use about 5 lines of code to create a temp string, then cast the integer as a string, then append the strings together

but theres got to be a simpler way...
 

textual

macrumors newbie
Original poster
Aug 24, 2008
6
0
i think i got it a little more streamlined now...

Code:
NSNumber *current_thing = [[NSNumber alloc] initWithInt: 1];
NSString *thing_string = @"thing ";
self.title = [thing_string stringByAppendingString:[current_thing stringValue]];
 

textual

macrumors newbie
Original poster
Aug 24, 2008
6
0
im a pure n00b with the cocoa and objective c
but it sure seems like cocoa tries to make things difficult...

so i have a value...current_thing
and i want to have buttons on the left and right for previous and next thing
but trying to add 1 and subtract 1 from current thing to use as a string for the buttons is a chore

i see that NSDecimalNumber supports decimalNumberByAdding
seems odd that NSNumber alone cant do a + or -
 

Taum

macrumors member
Jul 28, 2008
56
0
If you don't need an object (e.g. if you don't store it in an Array/Dictionary), use a simple C int instead.

To create your NSString, see [NSString stringWithFormat:...]
 

textual

macrumors newbie
Original poster
Aug 24, 2008
6
0
i do plan on holding on to the variable, as it will be used to display the title
thing 1, thing 2, etc

so i need it to stay alive in the class and also be able to perform simple add subtract functions
 

Taum

macrumors member
Jul 28, 2008
56
0
Instance variables don't have to be objects. They can be standard C types (scalars, pointers, structures, etc.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.