Nothing in my header shows up in Interface Builder

Discussion in 'iOS Programming' started by calistra, Dec 14, 2010.

  1. calistra macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #1
    I am new to IOS/Objective C but programming in C++ / C / Java and a dozen other languages for decades...

    I built the HelloWorld program on the IOS site - no problem.

    Now I am trying to work my way through the samples in "iPhone SDK development".

    I have a class MovieViewController

    in the header file
    Code:
    #import <UIKit/UIKit.h>
    
    @interface MovieViewController : UIViewController {
    	UILabel	*titleLabel;
    }
    
    @property(nonatomic,retain) IBOutlet UILabel *titleLabel;
    
    - (void) (IBAction)edit;
    @end
    
    BUT - I added a button in IB to the MovieViewController xib file and Ctrl Click the file owner and neither the property nor the action show up so obviously I cannot link the action to the button.

    I only added the property to see if it would show up after having failed to get the action.

    I have tried multiple variations of the action e.g.
    Code:
    - (IBAction) edit;
    - (IBAction) edit: (id) sender;
    
    but nothing ever shows up in IB.

    Am I really doing something stupid here?

    Help appreciated.
    Dave.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Perhaps. Have you saved your header file before opening up IB?
     
  3. calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #3
    'fraid so.

    I hit that problem the first time round.

    I added a method implementation and built it, closed the project and re-opened it all just in case...

    No luck.
     
  4. cnstoll macrumors 6502

    Joined:
    Aug 29, 2010
    #4
    I am not completely sure if this is required or not, but usually when I am linking an action and a button in IB, I define the UIButton as an IBOutlet in the header as well. I don't know if it's a requirement or not, but I suppose it's worth a shot. If nothing else, then you can modify the button parameters in code if you need to later.

    Aside from that, when you say "control clicking" does that mean you're actually trying to control click on the button or file's owner in IB and drag from one to the other? I'm not in front of my computer so I can't verify and therefore could be mistaken, but for what it's worth I believe the list of available IB properties only shows up when you've dragged and created a line to your destination.
     
  5. dejo, Dec 14, 2010
    Last edited: Dec 14, 2010

    dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Just FYI: it's not required.

    And no warnings from the build?

    P.S. The code looks fine to me, other than the:
    which has two return types.
     
  6. calistra, Dec 14, 2010
    Last edited by a moderator: Dec 14, 2010

    calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #6
    Ctrl-Click of File Owner is supposed to pop up a list of outlets and actions.
    It is not happening in this case.

    Dragging the Touch Up Inside method to the File Owner - the File Owner does not cause the File Owner to get highlighted in the usual way and the edit method does not pop up.

    EDIT:

    I originally tried without the (void) and the result was the same.

    No errors or warnings from the build.

    Run it and the button behaves like a button (turns a friendly blue).
     
  7. cnstoll macrumors 6502

    Joined:
    Aug 29, 2010
    #7
    In the inspector, double check to make sure the file's owner is actually pointed to MovieViewController class. I believe it's on the tab furthest to the right on the inspector.
     
  8. calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #8
    Another project has the same project with outlets

    I moved on to the next example and have a similar problem with the outlets...

    Code:
    
    
    #import <UIKit/UIKit.h>
    #import "Movie.h"
    #import "MovieEditorViewController.h"
    
    
    @interface RootViewController : UITableViewController {
    	NSMutableArray	*moviesArray;
    	MovieEditorViewController * movieEditor;
    }
    
    @property (nonatomic, retain) IBOutlet MovieEditorViewController * movieEditor;
    
    @end
    
    yet when, in RootViewController.xib, I right click the file owner, movieEditor does not appear as an available outlet - nor can I drag anything onto it to connect to it.

    I am sure I am doing something stupid (I am using an IOS 3 book to program IOS 4) - anybody had trouble like this before?
     
  9. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    cntl-click (and release) or right-click (and release) on File's Owner should show a black HUD window with the outlets etc. in it. This should happen regardless of anything else (I can think of). You get this HUD window for any object in the nib list.

    Make sure your View mode is list view.

    Is the Type for File's Owner correct?

    In the bottom left corner of the nib window is an led icon and the name of the project. The led should be green, but it can also be yellow or grey to indicate errors. What color is it?

    The code you show in response #8 looks syntactically valid. However, one doesn't usually have IBOutlets that are view controllers. Is that really correct? Is the view controller inside the nib?
     
  10. calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #10
    The HUD does not show this property.

    The file's owner is RootViewController.

    The LED is Grey- the label is MovieTable.xcodeproj and the message is "There is no XCode project associated with this document. Interface Builder will synchronize with open XCode projects that contain this document.

    The book indicates that I should have a view controller here. I believe that this is done to associate another class/screen with the view/edit function of the table view.

    A view controller has been added to the NIB - I had to set the class by typing it the name did not appear in the list.
     
  11. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #11
    OK, given that error and the grey led then the problem is that your nib isn't associated with a project correctly.

    Is the nib in a project and is the project open in Xcode? If not then make it so. If it is in a project then how do you open the nib? Double-click in the project window in Xcode or something else?

    I think the problem is just that you don't have the project open in Xcode. I just noticed that if you click the project name next to the led in the nib window then Xcode opens the project.
     
  12. calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #12
    That's the crazy bit. I open the nib by double click inside the open project.
     
  13. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #13
    If the project really is open in Xcode and really has the nib in it then can you confirm that the nib is in the target? Get Info on the nib file and check that it's in the target.

    Another possibility is that there is a space or other "funny" character in the full path to the project. This can sometimes cause problems.

    What does happen if you click the name of the project at the bottom of the nib window?
     
  14. calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #14
    OK - I just reopened the project and it looks OK now :(

    I have a suspicion - the previous time I clicked from the resources view, this time I clicked from the project view (all files on display). I will check and report back.
     
  15. calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #15
    So much for foolish optimism.

    Yesterday lunch time I opened the project and all was well. I made NO changes.

    Last night and this morning I opened it and the button at the bottom is grey again and I cannot see the new outlets.
     
  16. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #16
    I haven't run into this kind of problem but there have been various reports of similar problems on the Apple iPhone forum.

    Are there any funny characters, like space or accented characters, in the full path to the project? Is the nib file inside the project folder? Have you changed the name of the project after it was created?

    Choose Clear Menu in the Xcode Recent Projects menu.

    What happens when you click the name of the project in the nib window?
     
  17. calistra thread starter macrumors newbie

    Joined:
    Dec 14, 2010
    Location:
    Singapore
    #17
    Funny Characters - only me :rolleyes:

    I came across this which seems to work - do not open from recent projects, instead, open by double clicking the project file. Seems OK on first try.
     

Share This Page