开发者

Subclass of UIView with Xib file

开发者 https://www.devze.com 2022-12-26 20:48 出处:网络
Although I\'ve searched the Board and used google, I di开发者_StackOverflowdn\'t get any useful results.

Although I've searched the Board and used google, I di开发者_StackOverflowdn't get any useful results. I've trying to make a subclass of UIView loading its view from a xib file.

My approach is the following: 1. Creating a subclass (named mySubclass):

@interface mySubclass : UIView {

}

@end
  1. Creating a view through: Add New File... User Interface View XIB

  2. Connecting the Xib and the subclass: In IB select the View and set the class to mySubclass.

  3. In my viewController I make an instance of my new subclass and add to my view.

    -(void)viewDidLoad {

    mySubclassIns = [[mySubclass alloc] initWithFrame:CGRectMake(0, 300, 320, 20)]; [self.view addSubview:mySubclassIns];

    [super viewDidLoad]; }

Result:

Noting shows up in my App :( If I don't set it up programmatically but rather with IB it doesn't work either. (Am I setting it up right when choosing a view in IB and set the class to myClass?)

I would be really thankful for your help!

Thanks in advance.


you need to implement

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

it's given by default in implementation file... you just need ti uncomment it and implement it with your nib name...

0

精彩评论

暂无评论...
验证码 换一张
取 消