Disclosure Triangles and making custom view appear

Discussion in 'Mac Programming' started by Chirone, Mar 2, 2009.

  1. macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #1
    i've seen this happen in some dialog boxes where you click the triangle and an extra part of the window appears

    what i want to do is click the triangle and make things appear in the scroll window. specifically i don't want the main window to resize, the main window has to stay the same size so things need to expand within a scroll window

    i've tried searching google because i know the code to do it must be out there somewhere.... but i can't find anything

    i tried searching 'interface builder disclosure triangle' and 'interface builder disclosure triangle tutorial'

    if anyone know how to do this or what i should be googling that would really be helpful
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    If you're just hiding and showing a view and you're not resizing the window, then just use NSView's setHidden: method and toggle it on and off with the state of your disclosure button.
     
  3. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #3
    thanks

    yeah, i do want to resize the thing because all the others views below it will need to move up to close the gap

    i eventually found in the documentation the bounds structure, but that ended up doing some really weird things... i found the frame structure and that works predictably

    although... how do i get the (0,0) coordinate of a window to be at the top instead of the bottom? it would make calculating its new size fairly easier...

    (off topic, but same goes with scrolls... how do i get it to start at the top instead of at the bottom?)
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Are you referring to the window or the view? These are different things and you need to use the right terminology or everyone gets confused ;)

    I would suggest you read up on views. If you aren't familiar with how they are laid out you will have some difficulty implementing this:
    View Programming Guide for Cocoa
     
  5. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #5
    woops, i meant view, my bad

    looking over that article now... strange how i never found it before
     
  6. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #6
    ok, is there a way to set the bounds of a view so that (0,0) is at the top left corner using the interface builder?

    i tried remaking the bounds for a view but everything inside vanished somewhere...
     
  7. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #7
    i take back my last sentence there about nothing showing up

    i got everything to show up, but is it possible to change the bounds inside of interface builder so that (0,0) is at the top left corner and i don't have to go into my code and keep flipping the bounds height?
     
  8. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    I'm not sure I fully understand. You can override isFlipped and return YES to use flipped coordinates where 0 is at the top instead of the bottom, but this isn't useful really unless you have existing data that relies on this. Just use things like NSMaxY() and NSMinY() instead.
     
  9. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #9
    hi kainjow,

    the problem is what you see in the interface builder.
    when you click on the measurements and look at the size and position fields the X Y W and H numbers are all in respect if the origin was at the bottom left corner.

    can i change the interface builder so that the origin is at the top left corner so in the code when i resize the views it doesn't resize it as if the origin is at the bottom?
    i would have thought that anything you can do in code to do with layout you can do in the interface builder.......

    i would show you a screen shot of what i mean but i cant find where mac's equivalent of mspaint is
     
  10. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #10
    The origin is at the bottom left corner. If you want a view to be anchored to the top, you need to set its autoresizing mask.
     
  11. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #11
    well i gave up on trying to get interface builder to work, i should have mentioned before that playing with the autosizing doesn't actually have any impact on the output

    i made the code work, so when you click the disclosure triangle it goes and changes the height of some view

    i also have code that repositions the other views so that there is not giant gap between them

    the method i wrote works. it gets called successfully on start up and it does what it's meant to do

    however, as soon as a button is pushed any attempt at calling the method causes the program to crash.

    i love how objective c never tells you what the error is. all you get in the debugger window is the name of the method where the error occurred but you don't actually know what type of error you're looking at, whether it was an array out of bounds exception, or some other exception that's caused when things try to work again.


    to outline the method this is basically what it does:
    Code:
    int i <- 0
    name <- name at index i from array of names
    tempRectangle <- IBOutlet's frame from a dictionary with key: name
    tempRectangle.origin.y = 0
    IBOutlet's frame from dictionary with key: name <- tempRectangle
    
    for each other name in the array of names
        find the IBOutlet with key: name
        adjust it's origin.y position to be under the one above it
    
     
  12. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #12
    nevermind

    turns out that initializing a global array is only local
     

Share This Page