PDA

View Full Version : Disclosure Triangles and making custom view appear




Chirone
Mar 2, 2009, 03:04 PM
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



kainjow
Mar 2, 2009, 06:09 PM
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.

Chirone
Mar 2, 2009, 07:18 PM
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?)

kainjow
Mar 2, 2009, 08:52 PM
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 (http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaViewsGuide/Introduction/chapter_1_section_1.html)

Chirone
Mar 2, 2009, 09:03 PM
woops, i meant view, my bad

looking over that article now... strange how i never found it before

Chirone
Mar 3, 2009, 04:27 PM
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...

Chirone
Mar 3, 2009, 04:46 PM
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?

kainjow
Mar 3, 2009, 05:52 PM
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.

Chirone
Mar 3, 2009, 06:20 PM
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

kainjow
Mar 3, 2009, 08:58 PM
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.

Chirone
Mar 4, 2009, 04:16 PM
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:

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

Chirone
Mar 4, 2009, 10:13 PM
nevermind

turns out that initializing a global array is only local