dynamic value in nav bar title / dynamic views

Discussion in 'iOS Programming' started by textual, Sep 8, 2008.

  1. textual macrumors newbie

    Joined:
    Aug 24, 2008
    #1
    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...
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  3. textual thread starter macrumors newbie

    Joined:
    Aug 24, 2008
    #3
    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]];
    
     
  4. textual thread starter macrumors newbie

    Joined:
    Aug 24, 2008
    #4
    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 -
     
  5. Taum macrumors member

    Joined:
    Jul 28, 2008
    #5
    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:...]
     
  6. textual thread starter macrumors newbie

    Joined:
    Aug 24, 2008
    #6
    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
     
  7. Taum macrumors member

    Joined:
    Jul 28, 2008
    #7
    Instance variables don't have to be objects. They can be standard C types (scalars, pointers, structures, etc.)
     

Share This Page