Editing custom NSCell - macos

I'm in the process of creating a custom NSCell, which will work like the shortcut capture cells in XCode, and trying to figure out how to intercept edit requests (for instance, when a user double-clicks a cell). Is there some way to determine that an edit is being initiated?

Are you looking specifically to detect a double-click in a cell? If so, setDoubleAction:(SEL)aSelector is what you're looking for.
Or is the question more generically about detecting when a cell will enter 'editing' state? In that case, see the table delegate method tableView:shouldEditTableColumn:row:

Related

Trying to see the delegate of an NSTextView of an NSCell

I am having a devil of a time trying to figure out how to get the address of the Text Field Editor (NSTextView) of an NSCell—NSFormCell and NSTextFieldCell in particular? NSCell does not have a property to access it. I did figure out the editor is not allocated until one is actually editing the field.
I want to set the delegate so I can capture keystrokes for auto-completion.
By default, there's a single field editor for each window. Even if a control or cell uses a custom field editor, it's still vended by the window. You would call -[NSWindow fieldEditor:forObject:] to obtain the field editor for a given control.
However, the delegate of the field editor is always set to the control on whose behalf it is working. Setting the delegate to something else is likely to break things. So, you would typically use a custom subclass of the control and implement your delegate methods there.
Finally, controlling completions is normally done using -textView:completions:forPartialWordRange:indexOfSelectedItem: in the text view delegate, not by capturing keystrokes.

Custom UITableViewCell with UITextField editingDidEnd race condition

I have UITableViewController with Edit/Save button as BarItem. I have a custom cell which displays UITextField in edit mode. I am able to save modified text when I move focus to another cell etc. no problem. However my problem begins when I attempt to modify a field and press Save button that triggers setEditing:NO save etc. What I believe is happening is a race condition where Save action is triggered before editingDidEnd is processed and as a result I am not saving all of the data.
Any suggestions on how to handle this? Am I to go through all visible cells to save all of the data on save? I can definitely do that, but am I going to get into same problem with scroll and edit button clicked? Is there a better way to flush messaging queue?
Given that I have no takers, I think I am stuck with what I know:
in done/save (i.e. setEditing:NO) handling go through all cells and save their data
Keep updating data every time there is a change i.e. in Value Changed perhaps
attempt using UITextFieldDelegate and textFieldShouldEndEditing but I am not sure this would work since I will probably run into the same problem that I have.
I believe endEditing inside setEditing will solve the problem as it supposed to resign first responders for text fields.

Advice needed for developing multiple window Mac application

I’ve been reading through several books on Mac development, but cannot find the information I’m looking for.
The books all describe how to make floating windows or panes, but never mention how to make them all in one window. A simplified example of what I’m looking to create is shown below:
Basically, there will be three windows; A selector window with radio buttons to choose which NSDocument is currently being used, a window underneath that with buttons that show different windows to the right that allow viewing and manipulation of certain data.
For a example, each NSDocument may have a color value that can be set in the window shown by clicking view A, and some text strings that can be set in the window shown by clicking view B.
So the questions are:
Is it appropriate to use a single NSDocument sub-class for each Doc #1 and Doc #2?
Which classes should I use to set up the application as shown? NSWindowController? NSWindow? NSPanel?
I’m only looking for guidance on what to read up on, so any pointers are appreciated.
EDIT:
To clarify this further, I want to have a table view where the buttons are (View A & B), and by clicking them they will cause the other window/view to change it's contents.
It's like the split view in the iPad settings application, there is a table view on the left, and when it's pressed the right side changes.
The radio buttons are there only to illustrate that I want more than one Document. I'm guessing I need more than one to handle this? Or perhaps I should place them all in a single NSDocument? Somehow that doesn't seem right.
To achieve what you want you need one window (NSWindow), one window controller and various views each with their own view controller. There are several ways you could set this up, all depending on your requirements:
You'd have at least 3 views (instances of NSView): one for the selection of the document class, one for the view selection and one for the content. Each view is controlled by a view controller (instance of NSViewController). Additionally you can opt to wrap the views in split views (NSSplitView) so your user can resize the real estate available to each view.
You have one window with a window controller. If you choose a Document based app template in Xcode, Xcode will generate a subclass of NSDocument which you can use as your window controller (or choose to use Core Data and Xcode will generate a subclass of NSPersistentDocument with all bells and whistles you need to access Core Data for document persistency).
So to come back to your questions:
1: Yes, but depending on your requirements. If Doc #1 is a completely different thing than Doc #2 than you might need to re-evaluate. For example Doc #1 might have completely different persistent requirements than #2.
2: There's no single scenario here, but one that worked for me: Take the project template for a document based app (with or without Core Data). Use the generated subclass of NSDocument (or NSPersistentDocument) as your window controller. Use NSView to implement the views in your window where each view is managed by its own controller, which is an instance of NSViewController.
I know this is an old question, but a way to do it how you want would be to use: ContainerViews and set their embed segue to be the view controllers you want.

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.

Simply make a label say Hello World in Cocoa (Mac programming)

I'm a total newbie to programming in cocoa for the mac so this question is probably easy. I have a window, and on that window I have a Label.
I want to be able to update this label from my program with the current status or what's going on (eg. reading in file, parsing, etc.). My problem is that I don't know how to access the label and change it's text property. I tried "MyWindowName." hoping I would be able to reference the label from the Window. I don't even know what the labels name is, or even if it has a name.
How do I reference this label in my program to change it?
You probably need to go here and walk through some tutorials: http://www.cocoadevcentral.com/
A quick summary is that unlike other technologies, you don't access the controls directly (or shouldn't access them). Instead, you create outlets in a controller, which you then graphically connect to the controls and they update automagically. These tutorials will show you the way.
A label is just an NSTextField with different settings about editing/fonts, etc. Just make an outlet in your controller that connects to the view in Interface Builder, and you can change it like you would any other NSTextField.

Resources