I have been fighting for this for several hours: I want to create a custom UIView that is loaded from a NIB file. this is what i did:
1) I created a class and an NIB file named "MyView".
2) I placed the class as my own file owner class.
3) To download the NIB file, I know that I need this code, but I'm not sure where to put it. I put it in the "init" method.
NSArray * nib = [[NSBundle mainBundle] loadNibNamed: @"MyView" owner: self options: nil]; self = [nib objectAtIndex:0];
4) to use this custom view. Using IB, I created a UIView in my main ViewController. in the properties of the view in the user class, I put "MyView". I created an IBOutlet for this view called "myView" and connected it to the ViewController class.
5) now I'm not sure if I need to call "init" or if it runs automatically because it is in the NIB file. I tried both of them. in any case, the class type "myView" is recognized as a UIView, not as MyView and displays an empty view.
what am I doing wrong? is there another way to do this?
thank you Nimrod
EDIT: I changed my code according to the answers here. all the answers here did not actually use the user class, which is the whole idea here. this is what i did, but the application crashes because it thinks testView is a UIView, not TestView. please, help.
source share