Question

I am using XCode 4.6.3 to try iOS "hello world" like applications. I am able to create actions for UI elements using CTRL+Drag. My question is, how does XCode track which method is associated with a certain element. There is no such indication in the ViewController.m.

Was it helpful?

Solution

An XIB is a XML file. All information related to the UI is written to this file. Typically when you add connections from UIButton to its IBAction this is also written into the XML as connection records.

enter image description here

Also, after connecting all IBActions to its UI elements if you go to the XIB file and right click on File's Owner you can see that all the IBActions have associated elements.

enter image description here

And in the .h file the circles corresponding to the IBAction declarations fills with black color indicating that the action is now connected to a UI element.

enter image description here

During runtime, all this recorded information in the XML file is parsed and appropriate objects are created.

Hope that helps!

OTHER TIPS

You need to go into the .xib file and hover on the outlets and they will be highlighted in the view.

There is also a little circle in the .h or .m file that gets filled when an actual outlet is connected to that method/outlet in the .xib file.

When you open .storyboard in text editor such as TextWrangler you can see something as following:

<button opaque="NO" tag="395" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="5uG-EO-FFO">
                                    <rect key="frame" x="791" y="86" width="105" height="77"/>
                                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                    <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
                                    <state key="normal" image="button_image">
                                        <color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
                                        <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
                                    </state>
                                    <state key="highlighted">
                                        <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                    </state>
                                    <connections>
                                        <action selector="buttonPressed:" destination="YWJ-As-K1q" eventType="touchDown" id="PXt-9J-VMA"/>
                                        <action selector="buttonReleased:" destination="YWJ-As-K1q" eventType="touchUpInside" id="1QQ-SE-jT6"/>
                                        <action selector="buttonReleased:" destination="YWJ-As-K1q" eventType="touchDragExit" id="nqM-R3-G1j"/>
                                    </connections>
                                </button>

destination = your view controller - it's target of method 'selector' = name of the method

<viewController id="YWJ-As-K1q" customClass="SomeViewController" sceneMemberID="viewController">

That's all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top