views:

65

answers:

1

I'm new to developing in iOS and succesfully ran through a tutorial on how to create and connect outlets in a Mac OSX Cocoa App. However, when I try to follow the same process for my iPhone app, I keep hitting walls... (Apologies for the lengthy example- please bear with)

Project A:

In XCode:

  1. Create new Mac OSX Cocoa Application
  2. Create a new class SimpleViewController : NSObject

#import <Cocoa/Cocoa.h>

@interface SimpleViewController : NSObject {
    IBOutlet NSTextField *aField;
    IBOutlet NSButton *aButton;
}

@end

In Interface Builder:

  1. File > Read class files
  2. Drag SimpleViewController from my library into the main.nib
  3. Ctl-drag from SimpleViewController to view elements to connect my outlets

Everything above works great. Now for the same thing in an iPhone app:

Project B:

In XCode:

  1. Create new iPhone OS Window-Based Application
  2. Create a new class SimpleViewController : UIViewController

#import <UIKit/UIKit.h>
@class NSTextField;
@class NSButton;

@interface EmbedComplexViewController : UIViewController {
    IBOutlet NSTextField *aField;
    IBOutlet NSButton *aButton;
}

@end

(Notice my view controller is now an extension of UIViewController, not NSObject. Also, this time I need to use forward class declarations for my outlet classes. Not a problem, but is this necessary?)

In Interface Builder:

  1. File > Read class files
  2. Drag SimpleViewController from my library into the main.nib
  3. Ctl-drag from SimpleViewController to view elements - BUT now I can't see any of my declared outlet member variables. Instead, the only outlet option I have is 'view'

What more do I need to do to have my declared outlets show up?

Thanks- Yarin

+1  A: 

In iOS development, we use UIButton and UITextField and etc, (see the iphone developer documentation).

And no, you don't need to forward declare those classes (it made you since they weren't included in UIKit

Jesse Naugher
Thanks- simple enough!
Yarin