IBOutlet is nil inside custom UIView (Using STORYBOARD)

前端 未结 7 1566
忘掉有多难
忘掉有多难 2020-12-25 13:22

I have a custom UIView class. Inside it I have declared an IBOutlet property for UIImageView.

#import 

        
7条回答
  •  旧时难觅i
    2020-12-25 14:02

    I had similar problems, but I finally figured out what was wrong - It was a difference in the idiom between XIB files and Storyboards.

    In all the tutorials that I had seen with Xib files, if I had a UITableViewController create a DetailViewController to let me edit the content of the items in the table, then the tableViewController created an instance of the DVC once when it first revealed it, but then reused that same DVC instance whenever it needed to edit another item on the list.

    With storyboards, it appears that the a view that is revealed by a table view is typically created new each time the table view calls it up (and it doesn't call up the version of init that is in the UIViewController template). As a previous answer stated, you have to wait until "ViewDidLoad" to access any of the controls, even if you have shown this view before.

    I hope this helps.

提交回复
热议问题