Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ginjko

macrumors newbie
Original poster
Jan 10, 2011
3
0
I got a custom view displaying a picture and a path with a draw rect method, it loads fine and the drawing code works. But I need to update this view with a parameter that i get computed from an other class . I get this parameter update fine with a void method and at the of this method i got a setneeds display. but it does not work. If i put a self draw rect method it works but it draws my view on the bottom left corner.
I spent hours trying to solve this I just can t do it.

I attach my code to this post

Can someone help me ....
 

Attachments

  • moon_diplay_view.pdf
    28.2 KB · Views: 230
  • moon_diplay_view header.pdf
    20.9 KB · Views: 164
The origin of a view ( 0, 0 ) is the lower left corner by default. You can either learn how to flip a view and how to draw images in a flipped view (NSImage also needs to be flipped to draw right) or you can learn to deal with working from the bottom up.
 
as sydde said, you may need to filp your view.

Try adding to your view class implementation

Code:
-(BOOL)isFlipped
{
	return YES;
}

And for the setNeedsDisplay method. Just double check you are calling it on view class and not another class!
 
so to update the content of my view i should redraw it up side down and flip it again
 
so to update the content of my view i should redraw it up side down and flip it again

You need do only two things: tell the images that they will be drawing in a flipped view (look up the docs for NSImage, there is a method for this), and do your drawing with a top-down coördinate system in mind. I am pretty sure everything else takes care of itself.
 
My problem is that i call this void from an other class, and this is supposed to update K_imput, witch is the crucial value in my drawing.
If I update it through an IBaction and then call the set needs display it works but this value needs to be computed first by my other class and I can't enter it via an IBaction.

here is the void supposed to update this value.


- (void) set_k:(double)k_update;
{
k_imput = k_update;

printf(" K imput %f\n", k_imput);

}

I can read the value updating in the debuger console and it works fine,
but i have an other printf to read this same value inside the drawrect void.
And inside the draw rect void, this value stays nul.

Why !!!!!
 
Last edited:
Just a wild theory, but does your other class have a reference to same instance of your view?

If you put the following code at the start of each of your methods of moon_display_view:

Code:
NSLog(@"%s: %@", __PRETTY_FUNCTION__, self);

it will log the method name and a description of your moon_display_view into the debugger console. The description will include it's "address". Is the "address" always the same?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.