Xcode 4: Creating a UIView xib, not properly connecting

前端 未结 30 3430
时光说笑
时光说笑 2020-12-02 16:29

I\'m trying to create a nib that contains a view that will be embedded in a TableViewCell. I\'ve created the interface and implementation files, ResultCell.h an

相关标签:
30条回答
  • 2020-12-02 16:55

    I got into a similar state just today. It was very odd: I could attach any XIB (new or existing) to any already-existing ViewController class in the project, but I could not create a new ViewController and have it attach properly to any XIB. The "assistant" functionality didn't work, nor did the IB-to-headerfile-connection functionality.

    Closing the project and re-opening did not fix it.
    Quitting XCode and restarting did not fix it.
    Creating a new project and testing the functionality worked fine, which led me to believe there was something corrupt in some cache somewhere.

    My solution

    • Close your project.
    • Go to the ~/Library/Developer/XCode/DerivedData folder and REMOVE all subfolders there referencing the project you are working on.
    • Open your project in XCode. The problem should be fixed now.

    Incidentally, just running a full clean did not seem to clear things up. I had to trash the derived data. I'm certain I got into this position because of git games I was playing, but I had no idea how to get out, because even switching back to earlier git revisions didn't help. (That was a big clue also that it was something untracked by the project itself.)

    0 讨论(0)
  • 2020-12-02 16:55

    I noticed that .m file was moved inside en.lproj folder.

    Just delete (reference only) the .m file from the Xcode and moved .m out of the en.lproj. Add it again.It will fix the issue.

    Don't worry, you will get all your connections back.

    0 讨论(0)
  • 2020-12-02 16:56

    This might not work for your specific issue, but occasionally I get that error when working with newly created nibs. Deleting and recreating the nibs and View Controllers with the same names as before didn't resolve the issue, but relaunching Xcode did.

    0 讨论(0)
  • 2020-12-02 16:58

    Perhaps what worked for me is this.. (Xcode v4.5)

    This did not work

    I was trying to control drag into the interface definition of my .h

    @interface SearchViewController : UIViewController
    

    @end

    This worked (may be that is how it was supposed to work, I did not know it before) See the open and close brackets. Control drag and drop after the closed bracket.

    @interface SearchViewController : UIViewController
    {
    }
    
    @end
    
    0 讨论(0)
  • 2020-12-02 17:00

    This problem seems to be an Xcode bug which creeps up mostly when you replace a file with a new file of the same name. Xcode seems to keep a reference of the older file of the same name.

    Anyhow, the way to fix this seems to be:

    1. Clean the project
    2. Click (Your Project) in Project Navigator view. Go to Compile Sources under Build Phases of the target for which you are building. Remove and add back the .m file which is giving you trouble.
    3. Alternatively, in the File Inspector (Utilities view) of the NIB file, under Target Membership, uncheck and check back the target name.
    4. Restart Xcode for good measure.
    5. Of course, deleting and adding back the .m file alone should fix it too.

    (Steps 1 and 2 alone fixed it for me.)

    0 讨论(0)
  • 2020-12-02 17:01

    If restarting Xcode doesn't work of you, I have found that Toggling the new .m file out and back into the target membership works.

    0 讨论(0)
提交回复
热议问题