No response by clicking a button in Objective-C under Mac OS X 10.6.8 and Xcode 3.2.6 - interface-builder

What I do: I'm writing my first objective-c-software and I begun to write the code. First, it was thought o be a command-line-tool, which also was the type of project, I initially chose. After finishing, I added a new „Application Xib“-File, named „BedienOberflaeche.xib“ and created a GUI.
My problem: I try to get a response by clicking a button in my new GUI, but I get no response.
My research history: severel issues like creating buttons, connecting buttons with the object instance and something like „NSButton doesn't respond“. I couldn't find an answer, yet.
Relevance for others: This issue is relevant for all those, wo are creating their first objective-c-application and adding a GUI on it. I think, it is pretty basic.
My work platform: I'm working on Mac OS X 10.6.8 Snow Leopard and Xcode 3.2.6 on a MacBook 2,1. I found in the xib-file of the GUI the following:
Ed$ grep GuiPage FotobuchErsteller_0/BedienOberflaeche.xib
<int key="IBDocument.SystemTarget">1060</int>
<string key="IBDocument.SystemVersion">10K549</string>
<string key="IBDocument.InterfaceBuilderVersion">851</string>
<string key="IBDocument.AppKitVersion">1038.36</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
I already tried the following: My GUI contains one button, named „Selbsttest“. The graphic representation of the file „BedienOberflaeche.xib“ contains an entry, looking like a half-transparent blue box representing an object instance as subclass of „GuiPage.m“ after the connected class „GuiPage.m“ (no gap), which I configured under „Inspector“ → „Gui Page Identity“ (with gap) → „Class Identity“ → „Class = GuiPage“. The class „GuiPage.m“ contains code to execute after clicking the button. The object has a connection between the method „fuehreSelbsttestAus:“ and the entry „Push Button (Selbsttest)“, found at Inspector → „Gui Page Connections“ → „Recieved Actions“. „fuehreSelbsttestAus:“ is the name of a method, that should be executed by clicking the button. Besides that, I didn't perform any other configurations for the object.
The button itself shows a connection beween „fuehreSelbsttestAus:“ and the object „Gui Page“ under Inspector → „Button Connections“ → „Sent Actions“. Besides its title „Selbsttest“ in Inspector → „Button Attributes“ → „Title“, I didn't perform any further configuration in the other button concerning sections „Button Effects“, „Button Size“, „Button bindings“ and „Button Identity“ of the inspector.
The Method „fuehreSelbsttestAus“ can be found in the Class „GuiPage.m“:
#import "GuiPage.h"
#implementation GuiPage
//[...]
#pragma mark Methoden
-(IBAction)fuehreSelbsttestAus:(id)sender{
NSLog(#"Der Knopf zum ausfuehren des Selbsttests wurde gedrueckt.");
}
It should reproduce simple logging entries. I tried to run the GUI by starting „File“ → „Simulate Interface“ in the Interface Builder, which showed me a simulation of the GUI, but however, I can't see any logging after clicking the button „Selbsttest“.
I checked, whether there is a „GuiPage“ and a „Selbsttest“-button-entry mentioned in the .xib-file:
Edo$ grep GuiPage FotobuchErsteller_0/BedienOberflaeche.xib
<string key="NSClassName">GuiPage</string>
<string key="objectName">GuiPage</string>
<string key="className">GuiPage</string>
<string key="minorKey">GuiPage.h</string>
and
Edo$ grep Selbsttest FotobuchErsteller_0/BedienOberflaeche.xib
<string key="NSContents">Selbsttest</string>
<string key="label">fuehreSelbsttestAus:</string>
<string key="NS.key.0">fuehreSelbsttestAus:</string>
<string key="NS.key.0">fuehreSelbsttestAus:</string>
<string key="name">fuehreSelbsttestAus:</string>
The connection between the button and the object is mentioned there. Therefore I wonder, what can I do further to execute written code in the Method „fuehreSelbsttestAus“ by clicking the button. Has anybody an idea? I'd really appreciate any help.

The solution, as suggested, is to create an cocoa application and to transfer all the source code files in it. Obviously, the command line application type is not the right project type to be extent to an gui-based application.

Related

How to show a self-defined view as SCIM.app in the System preference - Keyboard - Input Sources

I am trying to intergrate our input method to the 10.10.3
And I found it's not easy to act like SCIM.app as the pic shows
I opened the activity monitor to see what file it opened (the SCIM.app was not running) As you can see in the following images:
The left shows the file list opened by System preference, and the right shows after I click the pinyin-chinese, the file list opened.
So I guess the little view was created by CoreChinese.framework. Since it was in /System/Library/PrivateFramework , It seems impossible for me to show this view as SCIM.app by a normal way.
I turned to nm and hopper disassembler...But I found it a long way to go
I guess you guys may encounter the same question, maybe you can help me.
Yes, I came across the same problems with yours.
1.It's easy to know that the view you saw, is provided by two part, the upper keyboard is a webview, which takes data in /System/Library/Input Methods/SCIM.app/Contents/Resources/*.keylayout, and finally shown by IntlKeyboard.prePane located in resources directory of Keyboard.prePane. and also you can find the actual html and pics, and 2nd part is a self-defined view provided by Preferences.prefPane.
2.Then 2nd part is to show the view you saw under the keyboard. as SCIM.app does, a file named Preferences.prefPane(must in the Resources directory of SCIM.app) was taken by IntlKeyboard.prePane.

How do I populate a popup button with AppleScript?

I've found this snippet of code in various place around the 'net:
tell window 1
tell menu of popup button 1
delete every menu item
repeat with catListItem in catList
make new menu item at end of menu items with properties {title:catListItem}
end repeat
end tell
end tell
When I use it in my AppDelegate script in a Cocoa-AppleScript Application, Xcode gives me an error: *t2t_AppDelegate.applescript:25: error: Expected end of line but found identifier. (-2741)* (Line 25 is "tell menu...")
I'm not sure what I'm missing that would allow me to dynamically populate the popup button with a list of terms (catList) that I'm drawing from another application. Any suggestions?
Unless you are running something earlier than Snow Leopard, It looks like you are using AppleScript Studio terminology (which was deprecated in Snow Leopard). Using the current AppleScriptObjC framework, the user interface items are referenced via outlet properties, for example:
property myPopUp : missing value
From the Interface Editor, this property is connected to your popup button, which allows you to use it with various methods in the NSPopupButton class and its parents, such as addItemsWithTitles. Once everything is defined and connected, you would use something like:
set catList to {"next item", "another item", "Items added"}
myPopUp's addItemsWithTitles_(catList)

Manipulating a Window in a Mac Application

I have the following code snippet:
NSNumber* windowNumber = [entry objectForKey:(id)kCGWindowNumber];
applicationName = [entry objectForKey:(id)kCGWindowOwnerName];
with this I grab the window number and the name from the window server of all Applications running.
What I want to do finally is to create a reference to whatever Window and manipulate its properties, for example if I have the window number of some instance of Safari, I would like to set it back or maximize it or maybe hide it. It is possible to do this ? some idea about how to start?
BTW I found this way of retrieve the "window number" and "application name" in an Apple Code sample Called Son of grab: http://developer.apple.com/library/mac/#samplecode/SonOfGrab/Introduction/Intro.html
if someone are curious.
Finally I accomplished this based on the apple sample Son of grab and by using the QUARTZ EVENT TAPS. This is a right way to filter events and manipulate other applications because it serves as a section 508 enabling technology.

Define the class of the sender when making an IBAction connection in Xcode 4,2.1

In Xcode 4 or above, it has a handy function allowing us to CTRL + drag an object from the interface to the .h file to quickly connect the object with an event method (assume the Assistant Editor is enabled).
Say we have an UIButton in the interface, and we want to add an IBAction for its "touch up inside", we enable the assistant window and press/hold CTRL + Drag the button to the .h file to quickly generate the necessary codes.
In the popup prompt box, say we set "connection" as "Action".
In the "Type" drop-down, we can select "id" or "UIButton". <--- this is where my problem is.
The strange thing in Xcode 4.2.1 is: no matter what I select, it always generates code: "(id)sender" as the argument.
I know it is easy to manually change it to "(UIButton *) sender", but what is the point of this drop-down when it always generates "(id)"?
Is this is a bug of Xcode or am I missing something to make it directly generate the code "(UIButton *) sender" when I select "UIButton" in this drop-down?
Edited on 27/Feb/2012: This is confirmed solved in Xcode 4.3
- (void)action:(id)sender is just the way actions are defined. you can, in theory, connect different UI elements to the same action. after you've created the connection, you can manually change id to whatever class you want, or just do a cast inside the method.

Why does setting initialFirstResponder have no effect?

I have a simple form (NSWindow) with 3 text fields. NSWindow's initialFirstResponder is 'pointing' to the first field (NSTextField). All three text fields are circularly linked to each other via nextKeyView.
Problem that I have is that when I start the application from Xcode it'll focus on the text field that was last active (in focus) when the application closed.
So for example, if I name text fields A, B and C and initialFirstResponder is set to A. Now if I start the application, focus on B, and close the application, next time I start it, the focus will be on B.
Why is that and how would I fix this?
(Sorry if this is a trivial question, these are my first steps in cocoa...)
EDIT:
This is on OS X Lion 10.7.1, Xcode 4.1.
EDIT 2:
I found a way to "fix" this... In the main window (or any window for that matter) XIB/NIB file, click on "Attributes Inspector", then uncheck "Restorable" box. Now the application will not store the last position and so the initialFirstResponder seeing will be respected and followed accordingly.
Welcome to Cocoa! :) I suspect this is happening as part of the new user interface preservation features in OS X Lion. (In fact, I just created a simple app with 3 text fields, and I see this behavior too.) Because windows automatically restore themselves, you will see a lot of this behavior happening automatically even if you didn't implement it. This is probably desirable — most applications will work this way, and the user will come to expect it.
However, if you really want to disable it, you can probably do so by subclassing NSWindow or perhaps NSTextField and overriding -encodeRestorableStateWithCoder:. But, I definitely recommend you leave the default behavior alone.
Edit with a little further information: the app state seems to be stored in ~/Library/Saved Application State/com.yourapp.savedState. There you can see a plist file with information about the windows. The other files don't seem easily readable, but they probably contain information about which field is first responder, etc.
Despite this thread being almost 10 years old I'll gonna add an answer. Just about one month after the answer from jbandes OS X 10.7 Lion was introduced.
Following a quote from NSWindowRestoration.h
#interface NSWindow (NSUserInterfaceRestoration)
/* Determines whether the window should be restored on relaunch. By default, windows with NSTitledWindowMask set in the styleMask are restorable, and windows without it set are not.
*/
#property (getter=isRestorable) BOOL restorable API_AVAILABLE(macos(10.7));

Resources