Using an Objective-C array with a slider to return custom values generates warning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StevenHu
    New Member
    • Oct 2009
    • 6

    Using an Objective-C array with a slider to return custom values generates warning

    I do not want my iPhone slider to return simple numbers like 1, 2, 3, etc. to the text label, but 15mm, 15.5mm, 16mm, etc., from 15mm to 45mm in increments of .5. So I thought I would put all the acceptable numbers in an array and link the slider output with the corresponding object in the array. (Slider returning "0" will link to the first element of the array, etc.)

    Here is how I've tried to link the output to the array, and the warning it generated (line 5, for line 4):

    Code:
    -(void)sliderAction:(id)sender{
    NSArray *array = [NSArray arrayWithObjects: @"15", @"15.5", ..., @"45", nil];
    NSString *labelValue; // This var will pass the value to the text label
    labelValue = [array objectAtIndex:slider.value]; // Slider will pass a number from 0-59
    // warning: passing argument 1 of 'objectAtIndex' makes integer from pointer without a cast
    label.text = [NSString stringWithFormat:@"%02.0fmm", labelValue]; // The array number and "mm" will be sent to the text label
    [labelValue release]; // release the memory
    }
    How do I change the type from a number to a string (I think that's what will take away the warning)? I've been coding in Obj-C for the last three months, and came from a PHP background.

    Thanks!
    Steve
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    Why not just multiply the number returned by 5?

    I am not at my pc now, but I think there is a stringwithforma t: that accepts an int.

    Comment

    • StevenHu
      New Member
      • Oct 2009
      • 6

      #3
      I will use several sliders in the app, and not all the sliders will return numbers as consistently spaced as these. Another array will have numbers that seem to be at random. That's why I'm using an array. If I get this one right, I'll get them all right.

      I don't see how multiplying an integer by 5 can get me 15.5.

      Thanks!
      Steve

      Comment

      Working...