Xcode 4: Creating a UIView xib, not properly connecting

前端 未结 30 3429
时光说笑
时光说笑 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:52

    Similar symptom, but different cause.

    Apparently I hit backspace when the focus was on the assistant view, because one of the standard file template comment lines went from // to / which results in the file not compiling.

    Fixing the comment allowed the SDK to parse the file, recognize it as a UIViewController, and add in the outlet.

    SO -- if you have this problem, do a build or analyze to see if there are errors that need fixing in your view controller .h file. THEN try the other solutions.

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

    I have had this problem and found a solution not listed above.

    In my case, I could see there was something wrong in the class .h file because my custom view controller did not recognise the class : UIViewController (it was in black not purple). All the other custom view controllers had the : UIViewController in purple.

    in my case, and possibly yours, I needed to add the class to targets/build phases/compile Sources drop down. The .m needs to be added. All of the other .m's were there but not this one.

    Once I added it, the :UIViewController appeared in purple and everything worked fine.

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

    For *.m file of this class view open "Show File Inspector" and unchecking "Target membership" for this project, then do Clean (menu Product->Clean) and checking again "Target membership" for this project

    enter image description here

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

    Using Swift, I had a similar problem. I found out that the comments were part of the problem for me.

    I leveraged the default view controller, did some work in it, then created a second view controller by copying the entire first one, stripping it down to only viewDidLoad() and renaming the class to TestViewController. Builds worked, code executed. All was good.

    When I went to drag a UITextField in to create an outlet, it would not let me. I noticed that my comments still said "ViewController.swift", so I changed the comment text to "TestViewController.swift" and rebuilt. I was able to connect my outlet!

    I wonder if what occurred is that the Indexer was reading the comments as well as the class names, and somehow got confused.

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

    Just put a line between the @implementation and the @synthesize. Most of the answers here have that in common. It worked for me

    @implementation 
    
    @synthesize
    
    0 讨论(0)
  • 2020-12-02 16:54

    I just tried everything here and nothing worked (using a Developer Preview for Xcode 5).

    The only thing that worked for me was to put this incomplete line in my interface file:

    @property (nonatomic, weak)
    

    For whatever reason, adding outlets and actions by drag and drop from a .xib worked fine after that.

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