IBOutlets not showing - xcode

I created three IBOutlets in a .h but when I go to Interface Builder and go to Referencing Outlets or right click on the object that I want to connect to one of the outlets. It just doesn't display the outlets I made. How do I find and connect the images in IB to these. My goal is to make custom buttons, I have the images out in IB and have set the highlighted state. And I want the images to auto switch to the highlighted state when touchupInside is triggered.
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController {
IBOutlet UIButton *brown
IBOutlet UIButton *red
IBOutlet UIButton *blue
}
-(void)brownPressed
-(void)redPressed
-(void)bluePressed
#end

If the code you posted is accurate, you are missing 6 semicolons. Interface Builder won't be able to properly parse the header file without them and so it won't show any IBOutlets.
Try changing the code to the following:
#interface FirstViewController : UIViewController {
IBOutlet UIButton *brown;
IBOutlet UIButton *red;
IBOutlet UIButton *blue;
}
-(void)brownPressed;
-(void)redPressed;
-(void)bluePressed;
#end

This answer is in reference to Xcode 4
If you changed the name of the .xib manually, don't forget to check these IB setting in the right pane:
Identity and Type: File Name
should be:
newName.xib
Custom Class : Class
should be:
newName
...
I was also experiencing this problem - after changing the .xib filename manually. I have no idea why renaming by refactoring was grayed out but that was my first attempted solution to rename. I then made some IBOutlets, but dragging to the File's Owner didn't give me any options to connect to it.
I right clicked on File's Owner and noticed some warnings telling me there was no IBOutlet by the name of the variable it tried to reference.
Basically, since I changed the .xib filename manually, at least one of the above configurations did not automatically follow (makes sense since I did a manual operation).

This happens to me try connecting the touch up inside connection of the button to files owner and then it will show up

Related

Finding stray IBOutlets

Is there a good way to detect stray IBOutlets prior to running?
Like if I added this code:
#interface MyViewController()
#property (nonatomic, weak) IBOutlet UIView *magicView;
#end
Then I connected it in Interface Builder. Some time later, I remove the outlet but forget to remove it in, say, my iPad storyboard. When I run the app, it'll crash with a KVO error at runtime.
IB shows a warning on them, but you need to click each view controller and search for yellow exclamation points. I'd rather just see a list, compiler warnings, something more prominent.
Interface Builder saves to XML files that can be examined in with a text editor in an effort to find zombie connections.

Can't CTRL+Drag NSButton to custom NSView header

I'd like to create a custom NSTableCellView instantiated by Interface Builder. I've set my Table Cell View class to MyTableCellView, and properly created MyTableCellView : NSTableCellView .m/.h files.
However, I just can't CTRL+Drag a simple button from inside this view to MyTableCellView.h in order to create an IBOutlet.
Here is a video to show what happens: http://youtu.be/sNNbuVT-SZs.
How the view is subclassed:
How I try to CTRL+Drag a button
Also, sometimes, Interface Builder just don't allow the cell view's class to be modified. What's happening ?
I finally found a solution, that is a little weird but works as expected. Instead of connecting the NSButton to MyTableCellView header directly, I used the reversed path:
Manually create an outlet:
#property(retain, nonatomic) IBOutlet NSButton* button;
Then click the empty circle on the left, and drag it to your XIB file's button:
I have no idea why it works this way, please let me know if you know the anwser.

NSMatrix access from code; initial layout done in IB

I am trying to access an NSMatrix object called "matrix" from my code. The object is generated in a NIB, but I keep having problems to access the object that was generated in the interface builder.
If my NSDocument has an NSMatrix *matrix, what should I do in the interface builder to link these two? And preferably, to use the initial layout from IB?
Thanks!
I think you are trying to create an outlet to the matrix. Just create a property in your .h file between the #interface and #end keywords:
#property (nonatomic) IBOutlet NSMatrix* myMatrix;
and then hold down the ctrl key and drag from 'File Owner' to the matrix object in IB. Make sure you
#synthesize myMatrix;
in your .m file between the #implementation and #end keywords and you should be able to access all of the properties via dot notation or message calls using:
self.myMatrix.somePropertyHere
I hope that helps!

UITextField text not changing on the UI

Once the code bellow is executed, the textfield's text doesn't change in the UI to "Fly" but the second NSLog does print "TextField: Fly" as it should.
#property (strong, nonatomic) IBOutlet UITextField *typeTextField;
....
UITableViewCell* cell = [self.theTableView dequeueReusableCellWithIdentifier:#"TypeCell"];
self.typeTextField = (UITextField*)[cell viewWithTag:1];
NSLog(#"TextField: %# ", self.typeTextField.text);
self.typeTextField.text = #"Fly";
NSLog(#"TextField: %# ", self.typeTextField.text);
Any help would be much appreciated.
You almost definitely forgot to connect the outlet for the UITextField in interface builder. Bring up the .xib file that that typeTextField is visible in, click on typeTextField, then show the Utility pane (the one on the far right in Xcode 4+). Click the Connections Inspector (the one that looks like a right arrow) and drag a New Referencing Outlet to your File's Owner.
When you don't connect the UITextField you drew in Interface Builder with the IBOutlet that you identified in your source file, both UITextFields get created as separate entities. You can make changes and work with the valid typeTextField with a broken IBOutlet, but it'll never appear on your view.
Consult How to connect an IBOutlet from an UITableViewController directly to custom cell? and http://www.youtube.com/watch?v=d_kO-J3DYvc on properly wiring your custom UITableViewCell objects.

Cannot connect UIButton to ViewController in XCode4

I'm learning iPhone Dev and I'm stuck on something. I'm writing a simple calculator program, but when I try to connect one of the buttons on the calculator to the File Owner in Interface Builder I do not get any options:
.h file
#interface CalculatorViewController : UIViewController
{
CalculatorBrain *brain;
IBOutlet UILabel *label;
}
- (IBAction)digitPressed:(UIButton *)sender;
- (IBAction)operandPressed:(UIButton *)sender;
#end
.m file
#import "CalculatorViewController.h"
#implementation CalculatorViewController
- (IBAction)digitPressed:(UIButton *)sender
{
//not implemented yet
}
- (IBAction)operandPressed:(UIButton *)sender
{
//not implemented yet
}
#end
As far as I understand when I'm working with my CalculatorViewController.xib in interface builder if I try to connect a button to the file's owner I should have two options:
1. digitPressed
2. operandPressed
However, I do not get any options. Any ideas what I'm doing wrong?
Thanks.
Check that file's owner is set to CalculatorViewController
In IB, click the button, then click the option on the far right (connections, I think it is called)
Find the action called touchUpInside. Drag from the circle next to this to your files owner, the two actions will pop up then.
Are you dragging from the button to the owner or the other way around?
If you want to refer to an object in a nib from code, then you define an IBOutlet and drag from the owner to the object.
If you want to refer to code from an object in a nib file, then you define an IBAction and drag from the object to the owner.
I encountered a similar issue.
The problem was that I renamed the ViewController.
The XIB file has the name of the view controller inside of it.
when it doesn't match the actual name of the UI View Controller class interface builder will act funny.
To fix it, open the XIB file as source code (right click it and use Open As source code)
it's an XML file. find the name of the old controller and then change it to the correct name.
I found it in the XML under:
<dictionary class="NSMutableDictionary" key="flattenedProperties">
<string key="-1.CustomClassName">xxxxxxViewController</string>

Resources