简体   繁体   中英

Presentation app with different UIView subclasses and XIB files

I am making a presentations app with that contains 50 slides. Each slide can contain buttons,videos,...

So I was thinking about doing it this way. I create 50 classes that are subclasses from UIView with each their own xib file. With this I can put different buttons on the UIView and use delegate methods to handle them.

Then I have one MainViewController with an header and footer image and in the middle one scrollView . I load up the XIB files like this.

  UIView *rootView = [[[NSBundle mainBundle] loadNibNamed:@"page1" owner:self options:nil] objectAtIndex:0];

Put all these UIViews in an NSArray and next place them inside a scrollView by looping the NSArray

for (int i = 0; i < arrViews.count; i++) {
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * i;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;

    UIView *view = [arrViews objectAtIndex:i];
    [view setFrame:frame];

[self.scrollView addSubview:view];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * arrViews.count,scrollView.frame.size.height);

So I have the following classes :

Page1.h (subclassed from UIVIew)
Page1.m 
MainViewController.h (subclassed from UIViewController)
MainViewController.m

What my question is now, how can I say that the UIViews that I created (UIView *rootView) should use the classes of Page1.

In the storyboard you have to change a Class to a custom class. So for example in your page1 XIB you have to go to Identity Inspector (3th tab) and in Class text box type Page1, and for next page you have to do it again. In that case you can call rootView like:

Page1 *rootView = (Page1*)[[[NSBundle mainBundle] loadNibNamed:@"page1" owner:self options:nil] objectAtIndex:0];

Hope this help.

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