Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access IBOutlets declared in superclass?

I'm currently refactoring a couple of view controllers that share a few IBOutlets and IBAction methods. I moved the outlet declarations and the IBAction method into a superclass, cutting these out of the subclasses.

Now, when I open up Interface Builder, I find that I can't see the outlets or actions declared in the superclass. The connections still exist, as I'd wired them up before the refactoring, but they're grayed out. (It's important to note that the connections also WORK, as my action fires on a button press, and my outlets are modified properly.)

The question is, how can I get interface builder to recognize outlets from a superclass? Is this possible, and, if not, what do you all recommend?

(Just for fun, here's my superclass header file:)

@interface TFMainViewController : UIViewController {
    UIImageView *logoImage, *thinkfunImage;
    UIButton *buyFullButton;        
}

@property (nonatomic, retain) IBOutlet UIImageView *logoImage, *thinkfunImage;
@property (nonatomic, retain) IBOutlet UIButton *buyFullButton;

-(IBAction) buyFullVersion;

@end

EDIT: in case anyone's wondering, I'm using Xcode and IB 3.2.5, with the iOS 4.2 SDK.

like image 233
Sam Ritchie Avatar asked Dec 13 '10 17:12

Sam Ritchie


People also ask

How do I unlink IBOutlet?

Select the view on the storyboard and then click the Connections Inspector. Then you can click the little x to remove an outlet reference.

How do you declare an IBOutlet property?

If you have a property defined that you want to make accessible to your storyboards, just add the @IBOutlet attribute before your property. Similarly with @IBAction to connect storyboard actions back to code. class MyViewController: UIViewController { @IBOutlet weak var likeButton: UIButton?

What is the difference between IBOutlet and IBAction?

An IBOutlet is for hooking up a property to a view when designing your XIB. An IBAction is for hooking a method (action) up to a view when designing your XIB. An IBOutlet lets you reference the view from your controller code.


2 Answers

I didn't realize it was even possible to connect to superclasses in interface builder until about an hour ago. Since this was the only question I could find regarding how to do this, I'll add my answer, even though this question is old. My answer is with regard to Xcode 4, not Xcode 3.

As far as I can tell, you can't connect to outlets in a superclass using the assistant editor, but you can do it by clicking on "File's Owner" in IB. That should show all the outlets in Utilities->Connections Inspector. You can then Ctrl+Click on the outlet in the inspector (click on the '+' sign), and drag it over to your view in IB.

like image 76
arsenius Avatar answered Nov 06 '22 13:11

arsenius


The solution for the problem with the IBOutlet .. is to change the class type to the Base Class in the identity inspector

enter image description here

connect using Control + drag and drop and

enter image description here

change it back to the child class

enter image description here

This works for me

BTW: i used Xcode 6

like image 20
Sosily Avatar answered Nov 06 '22 13:11

Sosily