简体   繁体   中英

IOS Custom UIView doesn't show

I'm sorry but i'm still a bit dumb in UIViews and creating a custom one.

I have a custom view and a xib file that are connected through the XIB IB.

I want to add this view to the storyboard.

What you see in this picture is an empty view which i've connected to the custom view class 在此处输入图片说明

When launching the app - i see the exact same view without my custom view being loaded.. what am i missing ?

It is not enough to just link your xib view to the storyboard through the view class name. You should copy the view from your xib (open your xib, select the root view and copy) to your storyboard view controller (select the parent view and paste). You can even open (double tap the xib file in the navigator) your xib in a new window and do a drag drop to the story board. Note that all the property wirings and constrains that you had defined in the xib will be retained when you copy paste your view from xib file.

The answer is actually pretty simple.

I had a recursive init process - meaning that although i did over initWithCoder method, in the xib file, i've set the view class to be my class.

What i should have done is to make my xib file's owner to be my class instead.

And then all the loadFromNibName worked perfectly in my initWithCoder!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM