Can the parent have less columns than child in NSOutlineView? - objective-c

I'm trying to implement outline view in my app using NSOutlineView, but in my app the outer layer (parent) should have only one column (Brand) and inner layer (children) should have 5-6 columns (Size,Type,Image, etc.).
Is it possible to achieve, and how to do so if it is?!

Yes, you can have “full-width” cells for “group rows” in a NSOutlineView (or NSTableView).
If you’re using a cell-based outline view, implement outlineView:dataCellForTableColumn:item:
in your NSOutlineViewDelegate. Before this method is invoked with any of the existing columns, it will be invoked with a column of nil. For the corresponding rows, return a prototype NSCell, and in your other data source/delegate methods likewise return the corresponding information for a nil “column”. You just need to create a generic NSTextFieldCell for this; no need to style it yourself unless you want to. More information in the documentation or take a look at some Apple sample code.
If you’re using a view-based outline view, implement the equivalent outlineView:viewForTableColumn:item:. Unfortunately the documentation is currently pretty nonexistent, but the corresponding NSTableViewDelegate method is documented, and you can look at this code sample.
The appearance of the full-width item will vary based on the highlight style (selectionHighlightStyle) configured for your outline view; from your description, it sounds like you would want “regular” rather than “source list” behavior.

Related

Select NSTableViewCell via Bindings (without tableView:viewForTableColumn:row:)

Can I use bindings to magically select the type of NSTableCellView that I want?
I've successfully transitioned from cell-based to view-based NSTableViews. Now I want to transition from using delegate methods to bindings.
Using delegate I implement tableView:viewForTableColumn:row in order to return one of three NSTableCellViews that I want to use (depending on the type of data). I set objectValue and the NSTableCellViews use that for displaying data.
Even now, with bindings, I can use the same delegate method to return one of the views; I simply don't set objectValue, and the I get objectValue from bindings. It works.
I switched to bindings as a learning experience, but also to get rid of this code. Maybe tableView:viewForTableColumn:row is specifically a delegate method instead of datasource method because this is still the expected way to select the correct view?
Is there a better (or rather, bindings-only) way to accomplish this?
One possible approach is to make one compound view that combines your three separate ones. You can basically embed your existing views into a tab view that doesn't show its tabs. Then, you can bind the tab view's selectedIndex or selectedIdentifier binding to a key path going through objectValue to pick which one to display.

Subclass UITableView for built-in search

Would it be possible (or advisable) to attempt to subclass a UITableView to have built-in search functionality?
There are two reasons I wanna do this:
Reuse: I could use the same subclass at multiple places in my project with different data-sources.
Cleaner code: It would de-clutter my view controller. All the plumbing for implementing search would be neatly incapsulated in the subclass implementation.
Any ideas how one would go about doing this?
Use UISearchDisplayController
From Apple doc,
A search display controller manages display of a search bar and a
table view that displays the results of a search of data managed by
another view controller.
You initialize a search display controller with a search bar and a
view controller responsible for managing the original content to be
searched. When the user starts a search, the search display controller
is responsible for superimposing the search interface over the
original view controller’s view and showing the search results. The
results are displayed in a table view that’s created by the search
display controller. In addition to the original view controller, there
are logically four other roles. These are typically all played by the
same object, often the original view controller itself.
It can be implemented as,
searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
UISearchDisplayController itself encapsulate all the normal search features. If you want you can subclass it to achieve whatever you are planning to do. You can use this in any class.
I guess I should ask for clarification: do you want the user's search to simply scroll to a row in the table, or do you want it to filter the rows, displaying only rows that match the search term?
Assuming you want it to filter the rows...
It would be pretty complicated to make a UITableView subclass to do this, because you'd need to interpose your own private UITableViewDataSource and UITableViewDelegate in front of the “user” data source and delegate.
It also might be rather inefficient, depending on how you get the data for the table view. If the table view can have thousands of rows, and they come from (say) a SQLite database or Core Data, the data source can search more efficiently for matching rows. In the table view, you'd have no choice but to iterate through the rows one by one, checking each for a match. Or you'd have to extend the data source protocol to give the table view a way to pass the search string to the data source... which seems like it defeats the goal of putting the searching in the table view.
If you tell us more about where the data comes from for your various table views, we might be able to give you better advice.

How to combine several iOS controls in one entity (control)?

I want to implement custom search and have one trouble. I need to combine UIButton, SearchBar in one control in order I can refer it by pointer.Then i will dynamically add more UIbuttons to that combined control.And the most important I want to manipulate this combined control as one program entity. For instance,CombinedControl* control;
So what the common way to implement this? Or may be I can emulate this?Thanks in advance!
If you're looking to combine multiple controls into a single unit, the simplest thing to do is just to add them as subviews of a single UIView. You can do this either in Interface Builder (by creating a blank UIView and dropping the other controls on it) or in code (using addSubview:). Then you just have a variable that points to the UIView that you added everything to.
If you want to add behavior to the "combined control", then you should create a subclass of UIView (as H2CO3 suggested above) and add the controls to that view subclass.

When using a view-based NSOutlineView (source list) using bindings, is it possible to not display rows from the data source based on some condition?

For example the image below shows an NSOutlineView bound to a tree structure based on folders and items using an NSTreeController:
What I want is the Item objects to remain in the model, but not to be displayed as rows, i.e:
The NSOutlineView delegate protocol has a method that informs the delegate that an item is about to be displayed, but doesn't give the option not to display it.
Is there some way in which to subclass NSOutlineView to implement this (or some other method)?
Thanks.
Presumably you're using NSTreeController which organizes your model objects according to the key path they use to identify their children.
If you want to filter anything out of the view, all you need to do is implement your child key path method to only return the children you want to display. (If you need to continue keeping track of the "real" children in your model, this may mean some extra bookkeeping to be able to return a separate list of children for display.)

The different of view controller and view in objective-c

I am new to Objective-c, I want to ask what is the different between view controller and view such as "UITableView" and "UITableViewController"?
What happen if I use UITableView instead of UITableViewController?
Thanks
You should look up the Model-View-Controller pattern in the Apple's documentation, since it is very important for using Cocoa. Basically, the idea in Model-View-Controller is a pattern for designing your class structure. Broadly, the model is where the application's data should be kept. The view is what controls the application's appearance and the controller is the place where the two are assembled. (Ideally, the view and the model classes do not even need to know about the other's existence).
Hence, the UITableView and UITableViewController are two different classes with two different purposes. The UITableView controls the appearance of the data and the UITableViewController "controls" the view (generally by passing it the correct data for display and layout). Since this pattern shows up again and again in Cocoa programming, you should take some time to become familiar with it.
They are two different things, they cannot be substituted for the other.
iOS follows the MVC design pattern, which stands for Model-View-Controller. The two classes you mention are 2 pieces of the overall puzzle.
The View is what gets displayed on the screen. That is its responsibility. So, the TableView is responsible for telling the phone what to render on the screen.
The View is also accompanied by the Controller. The controller decides what to do when something happens (user interaction, and other events that can happen at any time). So, the TableViewController is responsible for making the table do stuff (for example, telling the TableView what data to use for displaying on the screen).
So to sum it up, they are completely different, but they work very closely together in your application (you will almost always have 1 Controller for each View.
Well, the short answer is that one is the View and one is the Controller. Combine this with your data (the Model) and you have all the parts of MVC (Model - View - Controller).
Think of it this way, the UITableViewController controls the UITableview. They are complementary and they need each other to work.