How do I share an NSArrayController between two nib files? - objective-c

I have an array of images, and two nib files. One nib file has a window that displays the images in an NSTableView. The other nib has a window that draws the array of images into an NSView, and also draws a highlight over the images that are selected.
The array of images is controlled by an NSArrayController. I'm having trouble getting the two nibs to share the NSArrayController. I would have two separate NSArrayControllers bound to the same content, but I also want both nibs to share the controller's selection; that is, if you select an image in the table window, it also becomes selected in the other window.
Is there a standard way to do this?

I would have two separate NSArrayControllers bound to the same content, but I also want both nibs to share the controller's selection; that is, if you select an image in the table window, it also becomes selected in the other window.
Is there a standard way to do this?
Have two separate NSArrayControllers bound to the same content and selection indexes.

Related

Have Multiple UIImageView's From 1 UIImageViews

I have declared 1 UIImageView in my code. Is there a way to get multiple out of it? Say for example I have an imageView called red and position that on the screen. Is there a way to have multiple of red on the screen at the one time?
Thanks in advance
One image view is one image view.
If you want more than one, declare more than one.
If you have many similar image views, consider creating one array of many image views instead of a separate property for each one.
If you have all of the image views in a storyboard or .xib file, you can use an outlet collection instead of an outlet to store them.

Using the same custom table-view multiple times in one window?

I have created a table view in a nib that I want to use twice in the same window. The table view has its own controller, and I want to connect various parts as outlets. I can do that in the tableview's nib by setting the file owner to the view controller. However, how can I then get this tableview into the parent window?
It looks as if I can't do it through the interface builder?
So I have begun by creating two instance variables in the window controller for the two controllers. I assume I have to do this programmatically? How do I set the locations of each view correctly? Are there any side-effects from doing this? I am doing the window layout for everything else within the interface builder itself. I just can't see this working, however.
I also tried adding in a couple of scrollviews in the window where the table views would go. I thought perhaps then I could hook the scrollview up as an outlet and add them this way. At least then everything would be laid out correctly. This also doesn't seem to work though.

Can you assign different buttons for different views using a split view controller?

I am creating a split view ipad app. I have four buttons in the master view which segue to four different views. However, when I am in certain views I don't need all of those buttons to display in the toolbar. So basically, is it possible to change the buttons for different views in a split view controller? any advice, tutorials, or source code would be sweet
Adding to what Lu Yuan said. You could put a pointer to the instance of the master view in your app delegate so that when one of your subviews load, it can get the master view instance. Then you can hide which ever master view buttons you want.

Alternating between several NSViews

What I need may be pretty basic, but I'm definitely not sure as to how to proceed (I've done that before but none of my choices seem that Cocoa-friendly).
Ok, let's say we've got 2 NSViews - one next to the other:
The one on the left serves as a menu.
The one on the right will show a NSView (from a different XIB perhaps?) depending on the selection on the menu.
My questions :
How should I go about loading the different NSViews into the rightmost NSView?
How do I make sure that the subview (the one currently active) is properly resized when the window is resized?
rdelmar's solution should work, but another approach, which may be simpler, is to use an NSTabView to handle switching between the content views. You can hide NSTabView's tabs using the settings pane in interface builder, or by calling [self.tabView setTabViewType:NSNoTabsNoBorder]. I'd probably use a table view for the left side. When the user selects a row, you do something like:
-(void)tableViewSelectionDidChange:(NSNotification *)notification
{
[self.tabView selectTabViewItemAtIndex:[self.menuTableView selectedRow]];
}
The NSTabView can/will take care of properly resizing its content views as long as you've set up its and its content views' autoresizing masks (springs and struts) properly.
You should be able to create a custom view in IB that looks like your yellow view, and set its resizing behavior to expand in both directions with window resizing. Then, when you get your new view (by just referencing one you already have or loading a new xib), add it as a subview of the custom view, and set its frame to that of the custom view. I think that views resize their subviews by default, so it should resize correctly with the custom view.

Switching between two UITableViewControllers within a single UINavigationController

I have a UINavigationController. In its toolbar is a segmented control with two buttons. Each button relates to its own UITableViewController.
What I'm trying to achieve is someway of wiring up the navigation controller so that the views are switched depending on which button within the segmented control is active.
I assume I should hold on to the table controllers, because I want to preserve the scrolling position within each view, e.g., if the user was positioned at the top of table 1, and the bottom of table 2, then this information should be preserved when switching.
Any suggestions would be gratefully received!
Would it be possible to just switch the dataSource instead of having to deal with two separate table views? Preserving the scrolling position can still just as easily be done, and you end up using less memory (one table view and two data sources instead of two table views and two data sources).
With only 128MB to spare, memory efficiency is king on the iPhone.
Joel's suggestion is a good one. Another possibility is to use two different UITableViews in your view controller, and swap them out manually. There's nothing special about a UITableViewController; it's just a UIViewController with its tableView setup for you. Use a standard UIViewController, add two outlets for tables, hide one, and swap them when your UISegmentedControl is toggled.
I've used Joel's method. Very efficient.
Use the segmented control to call a method that sets a sets a variable, then sends [tableView reloadData].
Then the tableView: numberOfRowsInSection: and tableView: cellForRowAtIndexPath: retrieve their data depending on the value of the variable set by your segmented control's method.