View Full Version : dynamic value in nav bar title / dynamic views
textual
Sep 8, 2008, 11:35 PM
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...
kainjow
Sep 8, 2008, 11:37 PM
Post your code?
textual
Sep 8, 2008, 11:53 PM
i think i got it a little more streamlined now...
NSNumber *current_thing = [[NSNumber alloc] initWithInt: 1];
NSString *thing_string = @"thing ";
self.title = [thing_string stringByAppendingString:[current_thing stringValue]];
textual
Sep 9, 2008, 01:21 AM
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
Sep 9, 2008, 02:52 AM
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
Sep 9, 2008, 10:20 PM
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
Sep 10, 2008, 06:11 AM
Instance variables don't have to be objects. They can be standard C types (scalars, pointers, structures, etc.)
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.