Results 1 to 3 of 3
  1. #1

    Member Since
    Feb 14, 2013
    Absolute beginner: How do I read this...
    I'm new to ios deveolpment, but have a little prior knowledge in programming .net 1.0/2.0.
    Mij OOP skills are at beginner level still. I'm trying to learn to xcode using the book Objective-c for absolute beginners.

    I struggle mainly with the syntax of objective-c. I'm learning class basics and ui basics.
    An example from the book has me build an small app with just a label and a button. When the button is pressed, the label gets updated.

    Now, in the viewcontroller.h file I define the following property:

    @interface ViewController : UIViewController {
        IBOutlet UILabel *nameLabel;
    - (IBAction)showName:(id)sender;
    How do I read that line. The type is UILabel, the name is *nameLabel, but what is IBOutlet and why does that need to come in front of the property?

    Also, in the implementation file the label is set in the showName method

    - (IBAction)showName:(id)sender{
        [nameLabel setText:@"My name is ..."];
    Why do I also need to link the label to the owner in the UI (xib file)?

    Thanks for any answers!

    I hope these beginners questions are okay here ...

  2. #2

    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3
    First, these questions are perfectly fine here..

    IBOutlet and IBAction are special markers for Interface Builder. In code, they equate to nothing (nil in objective-c speak). They are used in your code to help IB figure out what to do.

    IBAction allows the UI to send your code an message when a button is pressed, and IBOutlet allows the UI to pull data directly from code if need be.

    So if your UI in IB had a button, you could have it send an action to something indicating it was pressed. IB would list the method showName: only when it sees the IBAction property before it.

    All of this is part of MVC (Model View Controller) design pattern. The idea being that your data is held in the Model, the UI components in the View and a object that marshals stuff back and forth in the Controller.

    This way the model (how you represent data) can change willy nilly while the view continues to look the same while displaying varying data depending on the model.

    You will learn a lot more about this when you get to Deletgates and things like NSListView as an example..

    Be sure to read the Community Guidelines | The more information you provide, the better answers you get, remember GIGO.

  3. #3

    Member Since
    Feb 14, 2013
    Thank you!

    I guess I am confused because of my (little) knowledge of .Net
    In .Net it suffices to update the labels text property using a method, as the showName method does. The extra steps of linking the two in the interface builder and declaring the label with the IBOutlet type are not necessary.

    Guess i'll have to get the hang of it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Xcode 4.2 - Absolute Beginner
    By hashman27 in forum iOS Development
    Replies: 6
    Last Post: 12-28-2011, 01:58 PM
  2. absolute beginner
    By myles.hunt in forum Switcher Hangout
    Replies: 18
    Last Post: 07-25-2011, 09:24 AM
  3. Welcome back, Absolute Zero!
    By Avalon in forum Schweb's Lounge
    Replies: 5
    Last Post: 01-13-2005, 10:25 PM
  4. from Absolute Zero
    By witeshark in forum Schweb's Lounge
    Replies: 3
    Last Post: 05-09-2004, 11:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts