Cocoa: how to reference lots of NSSliders - objective-c

I have this xib file for my main window, and it contains 64 sliders to be able to create a matrix mix for an audio application.
Setting the values using the sliders works, but I also want to save the values to the default preferences and load them back in the next time the application is started.
I have this working, but the sliders are not representing the actual values when the preferences are loaded.
How would i do this, without having to create 64 IBOutlets in my app controller?
I have the actual values in a NSMutableArray.

Maybe an outlet collection will help you?

Related

Changing collectionview button's image in Cocoa

Tools: xCode, Objective-C, Mac, Cocoa
Purpose: I am creating a collection view with many buttons.
Each button opens a file in a folder and each of them has a background picture of the file (for example: jpeg file) so it looks like what you would see in a folder.
Question: How to make each button have a different image? Also, is this too difficult for a beginner?
P.S. : If i did this without the collectionview option, I would just drag the button on xib and change their background images, however I need my window to be collapsable and scrollable, hence I am using the collection view.
I would very much appreciate any comments/help/answers. Thanks!
This should not be difficult. A CollectionView holds a collection of CollectionViewItems. Inside the Item you can create any views you need. One of them could be an NSImageView that you set at runtime to the image you like. I suggest to play around with CollectionView and some f the samples Apple provides on it.

How can I save NSWindow programmatically?

Basically I got an array of allocated windows and want to save their state (position/size/subviews) when the app is closed. Is there any way to do this?
When I try to use a NSUserDefault i get this error message: Attempt to set a non-property-list. Which turns out to that you can't save NSWindows in a user default. Should i use this instead?
//customView
[self setFrameAutosaveName:[NSString stringWithFormat:#"%d",self.tag]];
It's not usually useful to save the positions and size of subviews in a window.
Using setFrameAutosaveName: will save the window's position and size for a given name. The next time your app opens a document and creates a window with that autosave name, its state should be restored.
As for the size and positions of subviews, they are usually automatically laid out based on the auto layout system, or using Struts and Springs. Either that, or their positions and sizes are derived from data in your document model. Either way, you don't generally need to save them yourself. Why do you think you should be saving them? What are you trying to accomplish by saving them?

Lazy loading images in a UITableView that has a scroll index

I think this is a new spin on an old question, but I'm completely stuck here.
In my app, I have a UITableView with 650 cells, each with a custom 16x16 RGB icon. On most recent iOS devices, loading all of those icons into memory before displaying the table works totally fine, but on older hardware, I'd like to implement a lazy load system that only loads icons it needs.
I've implemented the Apple LazyTableImages example, (which uses a UIScrollView delegate to determine when the table stops moving to load the visible icons), but I've run into another snag.
My UITableView also has a section index display (ie the list of labels on the right hand side you can swipe up and down to scroll quickly), and the LazyTableImages example hasn't taken this into account.
If I scroll using the index, the images won't lazy-load. :(
As far as I can see, the scroll index doesn't actually have any delegate events it triggers.
So I'm wondering, has anyone else tried to implement lazy-loading on a table with a scroll index? Is there any way to track the index and find out if the user has interacted with it?
Thanks!
After buzzing around a few of my iOS developer buddies, I came up with a solution that worked well enough.
I set it up so that in addition to the icons being loaded from the UIScrollView delegates, an NSTimer object will periodically call a method that checks the currently visible table cells ([UITableView indexPathsForVisibleRows]) every .5 seconds, and loads any icons on the screen that haven't been loaded yet in a single separate thread.
I tried to make the solution as efficient as possible, so I made sure the timer was only active when the tableView was visible and stationary, and I liked it since it meant that every visible icon regardless was addressed.
One thing I discovered was that if the tableView was reloaded while the thread was looping through the visible cells (rare, but was possible), it would crash. The solution to this was to make sure each cell data source entry was retained while the icon was being loaded.

How to organize XIB files with many overlapping elements?

I have some XIB files which are very difficult to edit because many of the subviews overlap each other completely. For example, if I position a popup volume slider where it will pop up, it covers some UILabels which become impossible to click. My only chance to be able to edit them is to double-click on them in the Document window tree, move them aside, edit, then move them back. Sometimes there are 3 or more widgets that occupy the same location in the XIB, even though only a few are visible at a time while the application is running.
How are conditionally-visible screen elements actually supposed to be organized?
I would like to be able to hide groups of views to reveal what's beneath them, but I don't see a way to do that in IB.
If I create UIViewControllers for every group, I can edit them in separate windows, but I can't see them in context, and I need a lot of view controllers...
Tip: Hold down shift while right clicking the location of the object you wish to select.
I don't think IB is able to hide groups of views during design-time, but there's no reason you couldn't add that behavior yourself using an IB plugin.

Cocoa question for displaying images

I was wondering if anyone could tell me if there is a method in Cocoa that will display information (images) on screen when a button is pressed. What I mean is NSLog "prints text" to the console is there a method that displays images just as easily like would -(void)drawView do it? Is it just setNeedsDisplay? I hope this makes sense. I am essentially wanting to know if I can call something that will display an image as easily as you can display/print text to the screen/console.
The Console is text-only, so no, you can't print an image to it the same way you log text. The closest equivalent is to export the image as TIFF data and write that data to a file in the temporary directory.
As for setNeedsDisplay:, that tells AppKit that the view should be told to redraw the next time the window redraws its views. (In other words, it sets the view as needing display—exactly what it says on the box.) Usually, this is because you've changed the model object(s) that the view displays, either by replacing them with other objects or by mutating one or more of their properties.
You would need to have a view to display; an image view would certainly qualify, but if you're looking for the image equivalent to NSLog, this isn't it, unless you don't mind either making a dedicated window just for showing this image or temporarily putting a image view into one of your real windows.
You should take a look at Apple's NSImageView Class Reference.
This a class you can use to display an image in Cocoa.
setNeedsDisplay is a NSView method that tells the graphics renderer it needs to redraw the image because the data has been modified. Presumably because you are using something like Quartz and you have called some custom drawing code. If you are drawing bitmap images then you probably won't need to use this.