NSTableView textfield cell should not go into edit on click - macos

I have two NSTableViews in my app and both are set up the same, same parameters, etc., they have several columns with NSTextField cells and the first column is editable.
The first table behaves like I want it: if the user clicks, the row is selected. If the user clicks the row a second time the textfield goes into edit mode, letting the user change the text in it.
The second table should act the same but it doesn't: if I click a row in it, most of the time it goes straight into edit mode with the textfield. Very, very rarely this does not happen.
Does anyone know what causes this? I checked all parameters (in IB) and code and they are the same on both tables. If I set 'Refuses first responder' on the textfield in the naughty table, it doesn't let me edit the textfield at all so that option doesn't help.

SOLVED IT! The reason why it works on the first table view but caused the edit issue on the second table was because the first table allows dragging while the second did not! It seems somehow this interferes with doubleAction (I even read somewhere that an editable table cannot have doubleAction but it seems to work without problems). I could fix it by implementing tableView(_:writeRowsWithIndexes:toPasteboard:) in the second tableview's view controller and simply return false (since the 2. table should not have drag'n'drop ability) ...
func tableView(aTableView:NSTableView, writeRowsWithIndexes rowIndexes:NSIndexSet, toPasteboard pboard:NSPasteboard) -> Bool
{
return false;
}

Related

NSTableView as a form - nextKeyView issue (or how to force load all rows)

Perhaps using an NSTableView as a form is a terrible idea, but I've got it working pretty well in every respect except that you can't tab from field to field.
I have a table with a label column and a field column. I also have an array that keeps track of each row in the table with its accompanying NSTextField control. The controls are set in the array as they are loaded during tableView(tableView: viewForTableColumn: row:).
After the tableview is drawn, I run through each control in the array and set its nextKeyView to the following control.
This works swell, BUT only for those controls which have been displayed on screen. Because the control isn't added until it's loaded, table rows which are off-screen aren't hooked up.
My current approach (which is awful) is to manually scroll the table several times in order to force everything to load, then set all the nextKeyViews. I haven't got it working very well yet, so I was hoping someone had a better idea. Force-loading all views, if it works, should be an OK solution, but there may be something smarter out there too.
I guess the answer is
table.scrollRowToVisible(<row>)
This will show the row you want to see.

reloading tableview after a segue

I have a series of table views that 'drill down' to a final view controller. After the user has filled in a few text fields, it pushes to another one which is a congratulatory screen! Amazing I know. I've put a 'home' button in which (as it is a storyboard) then pushes to the first screen. Unfortunately the table is now not populated.
Do I have to implement some code such as [reload data] in the prepareForSegue method or is there a better/correct way to do it?
Any help would be much appreciated.
Presumably you have an array that provides values for the table and this array gets updated somewhere. Without much else to go on, I'd look at keeping a BOOL value that records whether that array has been changed. Then, in viewDidAppear, call [table reloadData] and reset the flag if there have been changes.

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

How do I reset a table view?

I have a table view in an iPhone xcode tab bar application that shows data either alphabetically or numerically, depending on a user selected option in one of the tabs. It works for the most part, but when I change the option and then go back into the table view, the table view initially looks like it did before the option was changed. However, as new cells get scrolled into view, they have the new display mode.
I can identify when the option changes, but I can't seem to get the code correct that would re-initialize the cells such that the next time they come into view they have the correct values. The data comes from a static array with set values, so I don't want to do anything with the data source, just the table view.
In other words, once the display option changes, I want to wipe out the table view I have so that the next time the table view displays it will show the correct data right from the start rather than after scrolling occurs.
Any help would be appreciated. Thanks.
It sounds like you want to call reloadData on the TableView.
[yourTableView reloadData];

CoreData-bound NSTableView loses input focus when items change, but only if sorted

I have an NSTableView in a dialogue box which is bound to a collection of CoreData model instances via an NSArrayController in 'Entity Name' mode. The table displays the names of the array of managed objects in a single column. This works well.
The names in the table rows are editable. If the user edits a name when there is no sorting applied to the table then editing proceeds normally. After pressing Return, the new name is recorded and input focus stays in the NSTableView. However, if the column heading in the table view is clicked upon in order to sort the table of names, input focus goes astray after editing. It stays within the window, or wider view (not sure which), but it goes out of the table; the focus ring vanishes and the background colour of the highlighted item changes from blue to grey. Pressing Tab pops input focus back into the table view again.
This only happens if the table contents are sorted. If "Continuously Updates Value" is chosen for the binding, it's catastrophic as the minute any characters are entered, the table view seems to want to re-sort itself (that's OK) and focus jumps out of it (that's not OK as the user was in the middle of trying to type something).
As far as this aspect of the system is concerned, there's no code - it's all done with bindings established in Interface Builder. Presumably, I've inadvertently set or cleared some option that I shouldn't have.
In case it helps the reader figure out what's up - I also have a modal sheet attached to the dialogue box containing the NSTableView. The sheet is used to edit the details of an item selected in the table view. The controls in this are also connected with bindings to the CoreData model using the same NSArrayController as the dialogue box 'behind' the sheet. The same problem is seen - as soon as a new name is typed in, focus is pulled back to the dialogue box 'behind' the modal sheet.
The only code involved is that used to handle the 'edit this item' action and start the modal session for the sheet.
What's going on? Where is the focus going and why is being moved just because of re-sorting in the NSTableView?
Thanks!
The entities NSArrayController had "Auto Rearrange Content" ticked in the relevant Interface Builder inspector panel. This wasn't doing what I thought it would do and was the cause of the focus stealing problem.
I finally narrowed this down by creating a bare bones CoreData application which just added names to a table view. Almost no code required; 99.5% Interface Builder and bindings, with just an extra outlet and a single line of glue code to tell the array controller for the CoreData model about the Managed Object Context instantiated in the application delegate by code that Interface Builder had auto-generated. Setting the "Auto Rearrange Content" flag in the test program provoked the same strange input focus behaviour.
So if you've got focus stealing problems with a table of objects bound to CoreData through an array controller, check your array controller's auto-rearrange flag!

Resources