Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBOutlet not connecting in Interface Builder- Xcode 4.2

I have read other questions here, but they seem to be for Xcode 3.2 or earlier, but nothing for 4.2. :(

I started a simple project and was wanting to connect the File Owner's Outlets within my xib. The bummer is that my IBOutlet's from my ViewController.h aren't coming over.

I don't have a reputation of 10 or above, so here is a screenshot of my File's Owner not showing my IBOutlets.

Here is my ViewController.h code:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController { 
    IBOutlet UITextField *txtName; 
    IBOutlet UILabel *lblMessage;
}

@property (nonatomic, retain) IBOutlet UITextField *txtName;
@property (nonatomic, retain) IBOutlet UILabel *lblMessage;

- (IBAction)doSomething;

@end

Here is my ViewController.m code:

#import "ViewController.h"

@implementation ViewController

@synthesize txtName;
@synthesize lblMessage;

- (IBAction) doSomething
{
    NSString *msg = [[NSString alloc] initWithFormat:@"Hello, %@",txtName.text];
    [lblMessage setText:msg];
}

@end

I am new to Objective-C and Xcode, so I could have made a mistake, but I've followed many tutorials and I can never get my IBOutlets to show. I have gone as far as to delete Xcode 4.2 and re-installed to try and fix this issue. Here is a screenshot of my Xcode Version 4.2, Build 4D199 info.

Anyone else run into this issue? Thanks anyone who can point out any mistakes I have made. Please let me know if more information is needed.

like image 827
scared Avatar asked Nov 30 '22 07:11

scared


1 Answers

When you create your IBAction, in the .h file, there will be a connection indicator to the left of it. When it isn't connected it shows a empty circle.

Press and hold this and drag it to the item you want to connect it to. I usually open up the XIB in a new window by double clicking it.

Connect the IBAction to your button by dragging from the the .h file


If it wont connect you must set the File's Owner in the XIB file. Select File's Owner in the Placeholders panel. Move over to the Utilities panel and make sure the Custom class, in Identity Inspector, is set to what ever your viewcontroller is named.

Set files owner

I Hope this will help you.

Cheers!

like image 114
hellozimi Avatar answered Dec 04 '22 05:12

hellozimi