1

I try to put the value of lastPointX into a label text, but doesn't work. In the Interface Builder, I create two labels, the label for "x" value and the label for "y" value. Please If anyone knows the solution, please answer the question.

Thanks.

This is the code and the error.

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
        UITouch *touch = [touches anyObject];
        lastPoint = [touch locationInView:self.view];
        CGFloat lastPointX = lastPoint.x;
        CGFloat lastPointY = lastPoint.y;
        labelx.text == lastPointX;    // <-----  error: Semantic Issue: Invalid operands to binary expression ('NSString *' and 'CGFloat' (aka 'float'))


    }
nioan7
  • 19
  • 2
  • 8

3 Answers3

1

You are trying to assign a float value to a property that expects a string. Also you want only a single "=" and not two. Try this:

    labelx.text = [NSString stringWithFormat:@"%f", lastPointX];
Carter
  • 4,738
  • 2
  • 22
  • 24
0

You need to convert lastPointX to string with this:

[NSString stringwithFormat:@"%d", lastPointX];
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
pasine
  • 11,311
  • 10
  • 49
  • 81
0

An operand is something like =, == and !=. The reason that you are getting that error is because you can't compare a UILabel to a CGFloat, therefore making the operand invalid. I think you have mistyped = with ==. So change the == to =.

Next, you have to convert lastPointX to a string as notme said. You can do this by creating an NSString from the lastPointX float.

label1.text = [NSString stringWithFormat:@"%0.0f", lastPointX];
max_
  • 24,076
  • 39
  • 122
  • 211