I have recently completed the my first application using ASOC. It is a utility that I’ll use in my profession as an over-the-road truck driver. In the its current “foot print” I have 10 NSTextFields arranged in a column. That is the format that is best for MY needs. Other drivers may be better suited with a “foot print” that has the 10 NSTextFields aligned in a row. What is the best way to accomplish this?
Would it be better to have 2 different windows, one arranged vertically and the other arranged horizontally, both having all the NSTestFields linked to the same outlets and providing the user with a menu item to choose which arrangement they want.
OR
Would it be better to have the window resized and rearranged via program code?
I have one more question. This one is regarding the location of documentation. In the old ASS days, there was basically one doc that had almost everything I typically needed to write and ASS-based program. With ASOC it seems like the information is scattered all over the place. Is this the case or I not found the appropriate documentation yet? :rolleyes: What is the best way to find the information that I may need to complete a task at hand. It can be a problem not knowing what you don’t know! :lol:
For rearranging views I prefer NSCollectionView. It’s a view like icon view in theFinder and manage the rearrangement of the views itself. Just make the NSCollectionView resize with the window and change max rows and max columns to avoid seeing a scroll bar instead of rearranging the NSCollectionViewItems.
Thanks for the info. I loaded iconCollection, built and ran it and while I certainly like the way it looks, my knowledge of Obj-C is way to limited at this point to figure out how it works.
I did fail to mention that the window size itself would change from a vertical foot print to a horizontal foot print depending on the user’s preference. i.e., the window would either be short and fat OR tall and skinny.
I don’t mind the steep learning curve, it gives me something to do during my mandatory 10-hour breaks. Knowing WHERE to look for information would be very helpful. For example, I’d never heard of an NSCollectionView before, where would I know to look to find it or something like it?
I think another way to accomplish this might be with a matrix. I made a little demo program where I embedded a text field in a matrix and then changed the matrix to have 10 rows and 1 column. I also set the inter cell spacing to 4 in both the horizontal and vertical directions. In the autosizing part of the size pane of the inspector, I connected the matrix to the bottom and left sides of the window and a button to the bottom. I made the window w=170 and H=340 so that it is a little bigger than needed to contain the matrix and button. When you push the button, the followong code changes the matrix from a 10 by 1 to a 1 by ten and resizes the window:
script MatrixSizerAppDelegate
property parent : class "NSObject"
property theMatrix : missing value
property theWindow : missing value
property theFrame : missing value
on applicationWillFinishLaunching_(aNotification)
set theFrame to theWindow's frame()
end applicationWillFinishLaunching_
on push_(sender) --connected to a push button
if theMatrix's numberOfRows() is 10 then
theMatrix's renewRows_columns_(1, 10)
theMatrix's sizeToCells()
theWindow's setFrame_display_({theWindow's frame()'s origin(), {1050, 200}}, 1)
else
theMatrix's renewRows_columns_(10, 1)
theMatrix's sizeToCells()
theWindow's setFrame_display_(theFrame, 1)
end if
end push_
end script
As for the documentation, you might look at AppKiDo (http://homepage.mac.com/aglee/downloads), it’s a free download that organizes the docs in more convenient way.
I also thought about NSMatrix or NSTable to solve this problem I thought an NSCollectionView fits better here. The differences are an NSMatrix and NSTable uses NSCells or one if it’s subclasses while a NSCollectionView uses a view or one of it’s subclasses. Another reason I would choose a Collection view is that it doesn’t work with columns or rows like NSMatrix or NSTable. And in this case that’s a good thing.
Brad,
You mentioned the resize of the window. Did you resize the window of the sample project iconCollection? you can see that NSCollectionView automatically rearrange the sub views so when setting the resize settings to the window’s size you don’t have to worry about how the window is sized. The collection view handles it all for you.
There are a couple of things that I don’t understand from your post.
Why is this an advantage for a NSCollectionView is this case where he wants 10 text fields? When you put them in a matrix, they are text field cells, which is what a matrix is meant to handle.
Why is that a good thing in this case? It seems like he wants either a 1 by 10 or 10 by 1 arrangement of text fields which seems like a situation perfect for columns and rows. Also, having them in a matrix allows you to access them by their indexes, so you wouldn’t need an outlet to each one (maybe you can do that in a collection view too --I haven’t used one of those yet).
In any case, I think the easiest thing to do, he mentioned in his original post – that is to have 2 windows each arranged the way he wants, and then have a dialog or preferences window that allows the user to choose between them. This way you can set up everything to look the way you want in IB and switch between them with one or two lines of code.
Ric, thanks for the example code, I’ll check it out soon. (Tonight is NOT the night for that based on the day I’ve just had!)
DJ, I did resize the window in iconCollection. I like the way the resizing looks but the code was “over my head” at this point! :lol:
Ric is correct in saying that I want either 1 row of text fields OR 1 column of text fields. The window isn’t resizable by the user grabbing the bottom corner – it’s either tall/skinny OR short/fat.
Since this app is for my personal use, I’ll probably investigate/research both of the ideas presented. It’s not like I’m up against a deadline for completion.
Oh yeah, I DID download AppKiDo. Thanks for reminding me. I forgot I had it.
I finally had some time to look at this idea and I can’t figure out what you mean by this. I see 2 objects that are of type NSMatrix: a Radio Group and a Form. I tried using a custom view and setting its class to that of NSMatrix and sticking a text field in it, but I couldn’t find the way to set the number of rows and columns or anything about the inter cell spacing.
While I’m at it, the NSForm got me thinking. In my app’s current format there is a label next to each text field. I like that when the text fields are stacked vertically, but when the text fields are side-by-side would it be possible to have the labels placed above the text field using the matrix method you put forth?
Unfortunately, the NSForm objects are only vertical. To embed an object in a matrix, you don’t choose any of the matrix objects. Just put a single text field into your window, and then go to the Layout menu, choose Embed Objects In, and finally choose the matrix sub menu. You can then use the inspector to change the number of rows or columns, as well as the inter cell spacing and the size of the individual cells.
My most simple answer to your question is that brad doesn’t ask for a row column view, he asks for a grid (maybe without knowing it) so use a grid then. It’s not that it can’t be done with a matrix but I think it’s not the most beautiful solution and you need more code.
I do like to use the “most beautiful solution” that I can. Trying to find the most efficient and elegant solution to any programming problem is what makes it fun for me to do. I had looked at the NSCollectionView Programming Guide, and thought that it seemed complicated to set up. Yesterday, I took the time to study the PersonModel example given in the guide and attempted to convert it to ASOC. Initially, I tried a fairly literal translation, creating 2 classes in AS, with one just having a couple of property declarations, and the other creating objects of that class – but that didn’t work, and I don’t know why. But then I found that creating the “PersonModel objects” was really nothing more than creating dictionaries in an array, so implementing the example took nothing more than 3 property declarations and one line of code. It’s really cool what you behavior you can get from a collectionView with some hook-ups in IB and a line of code.
If you need only two different window views, use an window controller with two separate windows.
Resizing and rearranging windows and UI elements programmatically might be cool but is quite complicated
First I need to thank Ric for his help on getting CoreData to properly work in my app (which I doubt I could have done without his sample - but can’t imagine living without now that I understand!)
Now I’m curious about this! I’ve gone thru the iconCollection sample and looked at the PersonModel objects, but I’m “lost” as to how to get it to work with ASOC. I THINK I have all the IB stuff worked out, and understand the needed property declarations, but what is the one line of code to get the data from the dictionaries in the array into the view?