Xcode 4: Creating a UIView xib, not properly connecting

前端 未结 30 3428
时光说笑
时光说笑 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:47
    1. ResultCell should be a subclass of UITableViewCell
    2. You should not drag a UIView onto the empty canvas, you should drag a UITableViewCell
    3. You should select the cell and change it to be your subclass
    4. The owner is most often a controller with an outlet to the cell

    Everytime you want to load a new cell, call:

     [[NSBundle mainBundle] loadNibNamed:nibName 
                                   owner:controllerWithOutletToCell 
                                 options:nil]
    

    after loading, use the cell, and set the ivar/outlet to nil, ready for the next load

    there are other ways, but this is common

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

    None of the above workarounds resolved the connector issue for me so I shelved my pet project until I came across the following stackoverflow thread:

    https://stackoverflow.com/a/15873770/2846800

    I had been working on a large project in a previous version of XCode and had turned off indexing. By re-enabling indexing my issue is now fixed:

    defaults delete com.apple.dt.XCode IDEIndexDisable
    

    I can now use the D&D features of Interface Builder. I hope this can help others...

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

    If you copied files from other project just make sure you check the 'Add to targets' box

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

    For my case, I have multiple project with some other dependencies. I tried to solve it by deleting derived data or restarting XCode but it couldn't work. In the end, I tried the following method and it works:

    Go to target > Build Target Architectures Only > and set both Debug and Release to NO.

    Set this for all projects in the workspace and recompile to make sure there is no other errors. Maybe not making sense but somehow did it. During my compilation, I had other issues such as linker errors and symbols not found.

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

    There is also a diferent reason for the issue ... if you have created new cocoa class file with template other than ios ... i can happen...

    The solution would be to delete it and re create it with right template

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

    In XCode 7.1, adding the connector at a different point in my source file worked. The error I was getting referred to one of my variables as if it were a class (didn't make any sense). The error stopped occurring when I added the connector below that variable instead of above it.

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