I have been trying to figure this out for a few days now and still cannot understand how this works.
I have created a new AppleScript Project in Xcode version 13.4.1 and added a CheckBox and a Button. My goal is to try and so something depending on whether the CheckBox is Ticked or Un-Ticked.
I am extremely new to Xcode so I am most likely doing something wrong.
The reason for not showing real code is that I have nothing that works so I am asking if anyone can help me learn this by filling in the missing gaps.
The documentation for Xcode Applescript object seems thin on the ground to me or at least that's what I am finding.
Thank you
property checkBox : 1 -- bound to the value of the check box & is ticked when run
#START BUTTON
on startButtonClick_(sender)
-- if checkbox is ticked then show alert "ticked"
-- if checkbox is NOT ticked then show alert "NOT ticked"
end startButtonClick_
Update
It was suggested that including real code would be more useful which I do agree with so here is the latest attempt I have tried.
property checkBox : missing value -- bound to the value of the check box
#START BUTTON
on startButtonClick_(sender)
set checkBox to (checkBox as boolean) -- toggle
if checkBox is 1 then display alert "Ticked"
log checkBox
end startButtonClick_
The alert never shows but yet the log output shows 1 when the checkbox is ticked and 0 when its unticked when I press the button
There are two issues here, depending on exactly what you're trying to do.
If you are trying to connect the checkbox action so that it calls a handler when you click on the checkbox, follow this procedure:
Make a handler in your script (in your case, the startButtonClick_(sender) handler)
Open the xib file, select the First Responder object on the left
Go to the Attributes pane in the Inspectors area. You'll see a
box labeled 'User Defined', so click the '+' button to add a new
user defined action.
Use the name of your handler with a colon, not an underscore, e.g.: startButtonClick:
Set the 'type' to NSButton (or I suppose you can use the default 'id')
Select the File's Owner object in IB, go to the Connections Inspector, and make sure the AppDlegate is connected as the File Owners delegate.
It should be, but I tripped over that problem during testing, so...
Select the button-in-question in IB
Go to the Connections Inspector, and control-drag from the Sent Actions area to the First Responder, selecting your user-defined action (which should now appear in the popup menu).
Now when you run the app and click the checkbox, it will run the hander with a reference to the checkbox as its argument. You can query that using sender's state() to get the current value of the button.
If you want a static, global reference to the button so you can check its state anywhere in the script, you may run into a problem. In Xcode 12 and earlier script properties would appear as outlets in the AppDelegate popup menu, so that you could connect GUI elements graphically. Xcode 13 has an as yet unresolved bug that makes this impossible, but you can work around it to an extent by editing the xib xml directly. Ive detailed how to do that in this post.
Hope this helps.
Related
I recently updated to Xcode 11 and some of its user interface changed. in older version of Xcode there was options of accessing files in assistant editor using automatic or manual. but in this version of Xcode I can't see any manual option in assistant editor. so I am not able to add IBOutlet and IBAction methods to particular storyboard.
so can anyone tell me how to add these actions and outlets, that would be great help. thanks
By pressing the above button, Xcode will split the view and allow you to select a custom file using the file tree at the top.
You are correct.
The Manual option is no longer visible. You can still achieve the same result by doing a quick open using Cmd+Shift+O then type the name of any file you want to open. Press the Alt key and the file will open in the Assistant Editor Window.
As others have noted the new add editor button allows you to add new editors and open files into them. You could file a bug report but you may want to consider that you're likely to get a "works as designed" type of reply.
You can always change or add new keyboard shortcuts to get the behavior you want by viewing the preferences key bindings area and search for the command you want to shortcut.
Note
You can still ctrl+drag from storyboard to the class by the Adjust
Editor button in the upper right of the storyboard. Then just select
Assistant Editor on the list. After which you can make IBOutlets/IBActions.
open your storyboard, hold option key and select the file you want
In the documentation outline of storyboard, try to choose the "correct" item, which you want to set up outlet connections. Say you want to set up an outlet connection for cell of table/collection view.
View Controller > Collection View > Cell > Content View > Image View.
Try to select Cell, "Content View" or "Image View", then check the jump bar of assistant editor, you're probably able to switch to the .swift file you want.
Reference
I have created a default [Swift] Cocoa application. I attempted to Ctrl drag from the default Open button in the menu to my View Controller in the assistant editor, but nothing happens.
Is my approach wrong? I assume there is some kind of default file chooser dialog, but I do not know how to make it appear or enable the Open menu item. From the documentation I feel I could make one appear programmatically, but I want to enable the menu button.
My first attempt at an OS X program hit a wall very fast :-/
First, control-Click on Open, and see if it is already attached to a function. If so, click the x to detach it, then try again.
Second, be very sure that the Assistant Editor is presenting the correct file to do the control-Drag. I have found that I need to manually choose the correct file much of the time.
I can't uncheck the properties under "State" in the Control section for the NSTableView:
When I click on a checkbox, the sign disappears for 1 second and then it comes back.
Could you explain me why?
The solution is that I had no Columns in the table: Column = 0.
(I'm adding the columns programmatically).
Still this is a bug in Interface Builder user interface.
Able to uncheck with XCode 6 on 10.10.
From your image attached, your line break mode is shown as invalid value. This could have happened when you tried to edit the source xml of xib.
Did you try selecting a valid Line break mode. Also what version of XCode are you using.
I am curious about an issue in Coded UI Testing. For example I created a button named Button1. I did assertions and everything is fine. Then I changed this button's name to Button2. Now, do I have to write my assertions again or is Coded UI Test can suit in every different name change. Notice that I am not doing any input or parameter changes, I am just changing user interface. Thanks for your replies.
You should be able to change the test code easily to cope with a name change like that. Open the UI Map file in the UI Map editor; ie double-click on the uimap.uitest file in solution explorer. In the left hand pane expand the method and select the action that clicks the button. That should open the relevant control in the right hand pane. Alternatively just find the control for the button in the right pane. View the properties of the button and click on the ellipsis of the "(collection)" value of SearchProperties or the FilterProperties. One of the items shown should be the old name of the button, just rename it there.
Is there a quick way to jump to an action associated with a control.
Say there is a button on a XIB file that has an associated action. The way to find the code associated with this is rather tedious. Is there a short cut that can quickly jump to the code.
I am spoiled by Visual Studio - double click on a button and it takes you to it's handler
The fastest way I know to at least get quickly to the source file in which the action resides is the following:
select the button in the UI editor
hit ctrl+1 (this will open the “Related Files” drop down)
navigate to the “Sent Actions” sub-menu, e.g. via s, enter
select the relevant class (I think in this case there can only be one, so just hit enter again)
Once you are in the class, the action should be easy to find. If that's not the case, because your source file is so big, type ctrl+6 to open the “Document Items” drop down and start typing the name of the action. Once you see the action, select it via keyboard or mouse.
If you often don't know the name of the action, you will have to look it up before navigating to the class, e.g. by right clicking on the button.
I would advise to use ^+⎇+⌘+Enter to get to referenced code file. There you can search for #IBActions or #Outlets. If a UIButton has a segue attached, this method won't help to find it.
To review a list of actions, segues and outlets you can select an object on the storyboard and press ⎇+⌘+7 to open Connections Inspector on the right pane.