display int in cocoa

  • Hi,
    I am trying to display an int as a page number in cocoa so the user knows
    which page he is currently on.
    the page number automatically increments itself.

    I looked into NSTextview but could not get it to work.  Most methods accept
    type NSString in their setTitle or similar function- so is there a way to
    cast an int to NSString?

    What would be the best way to display the int in cocoa ?

    Error casting code:

    int x = 0;

    char *a =(char *)x;

    NSString* temp2 = [[NSString alloc] initWithCString: a];

    I am currently achieving this effect using setTitle of NSButton class and
    using a disabled NSButton as the output for the page number.

    current = [[NSString alloc] initWithFormat:@"%d",page];

    [CurrentPage setTitle:current];

    [current release];

    Thanks.
  • Try an NSTextField. An NSTextView is a little more complicated than
    what you need in this case.
    FWIW your casting code is completely broken, don't even try to go
    down that route. initWithFormat is more on the right track.

    On Oct 10, 2007, at 11:10 AM, Erfan Aleemullah wrote:

    > Hi,
    > I am trying to display an int as a page number in cocoa so the user
    > knows
    > which page he is currently on.
    > the page number automatically increments itself.
    >
    > I looked into NSTextview but could not get it to work.  Most
    > methods accept
    > type NSString in their setTitle or similar function- so is there a
    > way to
    > cast an int to NSString?
    >
    > What would be the best way to display the int in cocoa ?
    >
    > Error casting code:
    >
    > int x = 0;
    >
    > char *a =(char *)x;
    >
    > NSString* temp2 = [[NSString alloc] initWithCString: a];
    >
    > I am currently achieving this effect using setTitle of NSButton
    > class and
    > using a disabled NSButton as the output for the page number.
    >
    > current = [[NSString alloc] initWithFormat:@"%d",page];
    >
    > [CurrentPage setTitle:current];
    >
    > [current release];
    >
    >
    > Thanks.
  • > ... so is there a way to
    > cast an int to NSString?

      Two ways off the top of my head:

    int x = 0;
    NSString * numberString = [[NSNumber numberWithInt:x] stringValue];

      -or-

    int x = 0;
    NSString * numberString = [NSString stringWithFormat:@"%i", x];

    --
    I.S.
  • On Oct 10, 2007, at 11:10 AM, Erfan Aleemullah wrote:

    > I am trying to display an int as a page number in cocoa so the user
    > knows
    > which page he is currently on.

    The proper way to format an value for presentation to the user in
    Cocoa is to use an NSFormatter.  In the case of an integer, use
    NSNumberFormatter.  It's important to do this in order to ensure that
    proper locale-specific formatting is applied if required, or not
    applied if it's not.

      -- Chris
  • Am 11.10.2007 um 00:08 schrieb Chris Hanson:
    > On Oct 10, 2007, at 11:10 AM, Erfan Aleemullah wrote:
    >> I am trying to display an int as a page number in cocoa so the
    >> user knows
    >> which page he is currently on.
    >
    > The proper way to format an value for presentation to the user in
    > Cocoa is to use an NSFormatter.  In the case of an integer, use
    > NSNumberFormatter.  It's important to do this in order to ensure
    > that proper locale-specific formatting is applied if required, or
    > not applied if it's not.

      Or in other words: Our Arabic numbers aren't ;-)

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today