Preselect a row in NSOutlineView - macos

My app contains an NSOutlineView. When the user quits the app a reference to the selected row is stored in user defaults and I would like to use this to preselect the same row when they next run the app. I know the method is selectRowIndexes:byExtendingSelection: but I can't find out when to call it - the table is not yet populated in awakeFromNib but I don't know how I can tell when it has happened. I really don't want to just wait an arbitrary time - is there some notification or callback I can use?

The answer was to populate the outline view in awakeFromNib and then select the row in applicationDidFinishLaunching: in the app delegate.

Related

How to get notified of clicks in a view-based NSTableView

I have a view-based NSTableView containing a list of words. When the user double-clicks on a word, I would like to take an action. The words are not editable or selectable. How do I do this?
I have tried setting the target and action of the table view in IB, but it only calls the action method when the user clicks in the header of the table, not in one of the words.
I have tried setting the target and action of the NSTextField that the table cell view keeps in IB. This results in this error message being repeated in the console:
2018-01-02 14:14:32.080347-0800 WordExplorer[7089:21457459] Could not connect action, target class NSObject does not respond to -relatedWordClick:
However the target class does respond to the selector. (I connected it in IB directly, so clearly, it does!) It is also not a simple NSObject, so I'm guessing that something else is going wrong there.
I have tried manually calling -setTarget: and -setAction: on the NSTextField contained in the table cell view in my delegate's -tableView:viewForTableColumn:row: method. This has no effect, and the debugger shows that despite calling those methods, they do not set the text field's action or target method. (Though, given this is Xcode we're talking about, it's likely that's just a debugger display issue.) I get no errors in the console like when I make the connection in IB, but it also does not call the appropriate method.
Do I need to make custom view class and use that for the table cell view? Or is there a simpler way to get clicks (and preferably double-clicks) on words in my list?
Simply create an IBAction on the object you have as the NSTableView's target, and then set the NSTableView's doubleAction property to the selector for that IBAction, and you can handle double-click events easily.

NSResponder and multiple NSTableView - who sent message?

I've got two NSTableView in a single NSViewController, and each has their own NSArrayController to handle what exists. I'm now trying to wire up the Edit->Delete button. How do I know, when the delete method is called, 'who' sent that message?
Specifically I want to know whether I was clicked into the first table view or the second one when I then chose the Delete menu item. The 'sender' to the delete method is just the NSMenuItem so I can't back-track that to the table.
Get firstResponder of the window and follow nextResponder until you find a table view.

NSTableViewDelegate SelectionDidChange and getting notified when clicked again

I'm using the SelectionDidChange form NSTableViewDelegate to alter some data based on the selection and then have the NSTableView reload it again (which will alter the cell's custom control state).
This works great, but I cannot get any notification when clicking a row that is already selected.
I would need something like a "SelectionDidNotChange".
Anyone?

RootViewController need to resort/reload data array xcode 4.3

I'm implementing an example, in that example, I read in data from a database, put it in an array, sort it, and it's displayed using the RootViewController. The DB read and array load happen before the RVC code. So, it works, I get the data in the window created by the RVC and there's a nav controller there as well.
I want to add a button or something to the nav controller so that when you hit it, it sends a value back to the RootViewController.m file, then based on that value, I want to resort the array and display it once again in the RootViewController window.
I'm not sure how to do this. What changes would I have to make to the .xib and the RootViewController.m file?
Please, I'm a confused nube. %-0 Thank you very much.
There's a fair amount to this, so I'll give some general points and if any of them cause problems, it may be easier to work out smaller details.
In you RVC's viewDidLoad method, you can create a button and set it as the right or left button in your controller's navigationItem.
You can associate a tap on that button with a method in your controller that can do whatever you want when the button is tapped. (But a button doesn't send values, really, so you may have to explain more about that idea.)
I assume the RVC has a table view if you're showing array contents, so once the array (mutable array, I'd assume) is re-sorted, you can tell the table view to reload its data.
In answer to your secondary question, once you have resorted your array (or generally updated your data however you wish) you can force the table view to reload programmatically
[tableView reloadData];
Where 'tableView' is your instance variable pointing to your table view

ABPeoplePickerView - How do I get it to scroll to a selected record?

I'm using the ABPeoplePicker in a Mac OS X application. I've hooked up a button that changes the selected record to the default 'Me' record.
This works fine, and the record gets selected, but, I need to scroll the table to see the selected record.
NSTableView has the -scrollRowToVisible:(NSInteger)rowIndex method, but I can't find anything similar for the ABPeoplePickerView
There is a notification ABPeoplePickerNameSelectionDidChangeNotification that is posted when the selected record changes, but I can't find a way of plugging in a property of the record into the view so I can make it visible.
It will automatically scroll to your selection when using selectRecord:byExtendingSelection: for example:
[peopePickerView selectRecord:[[ABAddressBook sharedAddressBook] me] byExtendingSelection:NO];
Be sure you're passing NO for the byExtendingSelection argument.
PS: Previous poster is in iPhone land ;)
How about the scrollPersonToView method?

Resources