views:

2065

answers:

10

I'm having a weird experience. I create any type of iPhone application, add a UIViewController with Xib file. I can edit the xib file with controls and see them rendered if I run. Now i'm trying to add a few IBOutlets to the controller, so I add them to the .h file, synthesize on the .m file. Then i head over to Interface Builder to connect the outlets. I drag the UILabel to the UIView, and then i try to connect the File Owner (which my custom UIViewController), but all that i can select when i try to connect to the UILabel is "view", which is obviosly wrong. So I'm not able to connect IBOutlets to their controls in Interface Builder.

Any ideas?

+1  A: 

Are you sure the File's Owner is correctly set to your custom UIViewController and that you've saved your .h file after having added the IBOutlet keyword to the instance variable and property?

Ben S
+1 for remembering to _save_, it's the easiest mistake to make!
Timothy Walters
I am positive the type of the File Owner is the same as the custom UIViewController. I'm positive I have saved the .h file as well. Here is what the .h file looks like:#import <UIKit/UIKit.h>@interface gg : UIViewController { IBOutlet UILabel *label;}@property (nonatomic, retain) IBOutlet UILabel *label;@end
haider
That's just weird then. Have you tried deleting the `.xib`, `.h` and `.m` files and re-creating them?
Ben S
yeah. i tried all of that. rebooting too. weirder thing is my older projects don't give me that behavior, but new projects i create give me that experience. very strange.
haider
even if i check the connections tab on my custom view controller, i don't see the new outlets that i've added to the .h file
haider
does it help to add that none of the supportive "intellisense" hints are not working in the .m file.
haider
Do you have any compile errors or warnings? Usually, when auto-complete doesn't work for me, I messed up the brackets or parentheses somewhere.
Ben S
A: 

So I don't know exactly why it doesn't automatically make the IBOutlet connections, but i found a workaround. I had to manually add the outlets through the Library in Interface Builder for my customer view controller. If anyone finds the fix to make it automatically read from the .h file (like its supposed to), I'd be very appreciative if they posted it.

thank you

haider
A: 

I had pretty much the same problem as you did. I don't know if you solved your problem yet but mine was that I changed all the classes' names, including the viewcontroller, but the file's owner's name remain unchanged. So, I double clicked File's owner -> click i in the window opened -> change the name in the Class field to the new viewcontroller name. Then it worked. Maybe you want to try it again and see if it works. Good luck.

chepukha
+1  A: 

Did you make sure you are defining your outlets in your .h file as the appropriate type? If you are trying to connect a text field in IB, then your .h file should look something like...

IBOutlet UITextField *MyTextField;

Make sure the type is UITextField (or UITextView, etc). If you type them as NSString or anything the is not appropriate, then you can't connect them in Interface Builder....

Michael
+1  A: 

In Interface Builder File->Read Class Files, and point it to your File's Owner's class. That fixed it for me.

diatrevolo
A: 

I had the same problem, and I just tried diatrevolo's suggestion: Click File, then Read Class Files, and point to your File's s Owner class.

This fixed it for me. I would +1 diatrevolo, but I don't have any reputation yet...

martin jakubik
A: 

I'm a total newbie at this, and I had the same problem. I went to try diatrevolo's suggestion, and, in doing so, found out what was causing my problem. I had originally created my ViewController somewhere random in the project hierarchy, and then moved them into the classes folder. This meant that the actual files were not in the classes folder, but the project thought that they were, so IB was looking in the wrong place. I moved the actual files in to the actual classes file with Finder, and then deleted and readded them in the project. Then everything worked!

mk
+4  A: 

I did a combination of the things in this thread and I finally had success.

  1. File->Reload All Class Files
  2. File->Read Class Files (select MyClass.h)
  3. Reconnect File's Onwer by a. Setting the Class to "MyClass" b. Reconnecting the View to the File's Onwer's View

Everything is back to normal now. Weird.

Hope this helps more than it confuses ;-)

Kevin Fisher
Had the same problem, and this fixed it.
alexbw
Thanks Kevin, it saved me, otherwise i was pulling my head lol. But can you tell me why this all happen? Thanks.
itsaboutcode
A: 

After I localized some XIB files, the views did not react to any updates made in Interface Builder. Simple solution was to delete the app from the simulator / device. The next Build&Run updated the application correctly.

This only happened while deploying the app via XCode on the simulator. Seems like XCode is trying to optimize the build and gets confused.

Colins
A: 

File->Read Class Files (select MyClass.h) Did the job for me.

Mr H