469,304 Members | 1,888 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

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):

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
Oct 7 '09 #1
2 3726
markmcgookin
648 Expert 512MB
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.
Oct 7 '09 #2
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
Oct 7 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by j_mckitrick | last post: by
2 posts views Thread by David | last post: by
65 posts views Thread by Arjen | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.