NSTableView handling edititng cells correctly - cocoa

I have an NSTableView working correctly except when I'm editing one of the table items. If the user is still in edit mode, and it presses the Sheet OK button, the tableiew doesn't update.
How do I force the tableview to commit the changes when the user press the ok button (closesheet).
Also, how do I handle the ESC Key to cancel the editing?
Sorry if the questions looks absurd, but I've been only on developing on Mac for a month.

You should be able to call [sheet makeFirstResponder:sheet], where sheet is the sheet you are about to close. That will switch first responder status away from the text field, which will cause it to commit the in-progress edit.

I had the very same problem: How to add data from an NSTextField to a Core Data Attribute without having to press Return or Tab after editing the TextField?
There seem to be different solutions. If you use bindings to connect the NSTextField of your edit sheet to the ArrayController, you could check „continously update value“ in the TextFields value binding in Interface Builder.
Other solutions are explained very well in this blogpost at Red Sweater Blog: http://www.red-sweater.com/blog/229/stay-responsive

Related

Remove Focus from UITextField

I'm trying to remove focus from a UITextField and even though I resign it from being first responder, I'm still not able to have the cursor not focus on the text field.
I don't have any other input on the view to move the focus to and I don't want to create a dummy one either. What is a good workaround for this?
As per the documentation.
To dismiss the keyboard, send the resignFirstResponder message to the text field that is currently the first responder. Doing so causes the text field object to end the current editing session (with the delegate object’s consent) and hide the keyboard.
If you call resignFirstResponder on your textfield then it will end the editing session and the cursor wont be focussing on that textfield.
So please verify one more time whether resignFirstResponder is getting called on that textfield which you want to remove the focus.
Please try to set your current class as delegate of your UITextField. I think you forget to set the delegate that's why it's not working as you are expecting.

NSOutlineView NSTableRowView Loses Apparent Selection After Editing

I have a view-based outline view (OSX 10.7). Clicking on an item selects it, as usual. Double clicking allows editing of the textfield it contains. However, when I'm done editing the textField, the row's highlight disappears. The outlineView still thinks the row is selected, and sending that row a drawSelectionInRect message doesn't change its appearance. Telling the outlineView to again select the row also doesn't change its appearance. Only by again clicking on the row can I get the highlight to reappear. Any idea what's going on?
My fault. I'm observing changes to the managedObjectContext, and was reloading the entire tree when individual items changed: by correcting this to reload only the affected item, things work as they should.

How to put action on text in xcode?

I don't want to connect action to button, I want when user clicks text that says "Insert" to highlight that text (or change color) and call a function.
How to do that?
UILabel doesn't have a function inherently that you could use, however the UITextField has a property called editing that is called when the user taps the text. This may or may not be what you're looking for because the keyboard is usually open during editing of a text field.
In my honest opinion, it really would be easier to use a button in the long run. It's much less work to put an invisible UIButton on top of the text and check to see if the user taps that.

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!

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