質問

I am developing a document based cocoa app. The startup interface is modeled after GarageBand: A welcome screen is displayed, which shows one of two alternating views (switched through a segmented control): "Create New Project" and "Browse Recent Projects". Each of this views is controlled by a dedicated NSViewController (in this case NewProjectViewController and RecentProjectsViewController).

To achieve this, I subclassed NSDocumentController so as to show this "Welcome screen" on startup instead of creating an empty document (An empty document doesn't make sense in my app until the user specifies certain minimum settings).

After launch/initial document creation, if the user chooses "Create New Project..." (i.e., new document), I display a window that reuses the same interface as the "New Project" tab in the Welcome screen, by instantiating the same NewProjectViewController and adding its view to the window.

In both cases, the view controller' view is created from a .xib. The view controller itself is instantiated programatically and its view is added to a preexisting subview of the window using -addSubview:.

The view for NewProjectViewController contains several editable NSTextField instances, and other controls.

The problem: All the NSTextField instances in the view controller's view will accept text input only the first time; From the second time on that the view is displayed, attempting to edit the text will produce the system alert sound. The text can be selected (highlighted), but not changed. Also, the text can be changed programmatically.

The other controls (popup buttons) can be changed without problem.

I have tried showing the "New Document" window from the beginning (instead of the Welcome screen), but the result is the same: The first time it works, the second it doesn't.

Is this a first responder problem?

役に立ちましたか?

解決

OK, I fixed it (although I still don't know exactly why it wasn't working).

I changed both prompts ('Welcome' screen and 'New Project' window) to run as modal windows.

The 'Welcome' window calls -[NSApp abortModal] on 'Quit' and -[NSApp stopModal] on 'Choose'. The 'New Project' window calls -[NSApp abortModal] on 'Cancel' and -[NSApp stopModal] on 'Create'.

On the Document controller's side, I inspect each window controller to see what exactly the user selected and act accordingly (create a new document, open a recent document, do nothing, quit the app, etc.)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top