Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Oct 2009
Posts: 6
#1: Oct 7 '09
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):

Expand|Select|Wrap|Line Numbers
  1. -(void)sliderAction:(id)sender{
  2. NSArray *array = [NSArray arrayWithObjects: @"15", @"15.5", ..., @"45", nil];
  3. NSString *labelValue; // This var will pass the value to the text label
  4. labelValue = [array objectAtIndex:slider.value]; // Slider will pass a number from 0-59
  5. // warning: passing argument 1 of 'objectAtIndex' makes integer from pointer without a cast
  6. label.text = [NSString stringWithFormat:@"%02.0fmm", labelValue]; // The array number and "mm" will be sent to the text label
  7. [labelValue release]; // release the memory
  8. }
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's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Posts: 546
#2: Oct 7 '09

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


Why not just multiply the number returned by 5?

I am not at my pc now, but I think there is a stringwithformat: that accepts an int.
Newbie
 
Join Date: Oct 2009
Posts: 6
#3: Oct 7 '09

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


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
Reply

Tags
iphone, objective-c, pointer without a cast, xcode