custom view don't work after 3days trying

Discussion in 'Mac Programming' started by ginjko, Jan 10, 2011.

  1. ginjko macrumors newbie

    Jan 10, 2011
    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 ....

    Attached Files:

  2. Sydde macrumors 68020


    Aug 17, 2009
    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.
  3. kwfl macrumors 6502

    Aug 20, 2007
    as sydde said, you may need to filp your view.

    Try adding to your view class implementation

    	return YES;
    And for the setNeedsDisplay method. Just double check you are calling it on view class and not another class!
  4. ginjko thread starter macrumors newbie

    Jan 10, 2011
    so to update the content of my view i should redraw it up side down and flip it again
  5. Sydde macrumors 68020


    Aug 17, 2009
    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.
  6. ginjko, Jan 11, 2011
    Last edited: Jan 11, 2011

    ginjko thread starter macrumors newbie

    Jan 10, 2011
    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 !!!!!
  7. jiminaus macrumors 65816


    Dec 16, 2010
    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:

    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?

Share This Page