2014-02-27 20 views
0

我正在製作包含50張幻燈片的演示應用程序。每個幻燈片可以包含按鈕,視頻,...使用不同的UIView子類和XIB文件呈現應用程序

所以我想這樣做。我創建了50個從UIView開始的子類,每個子類都有自己的xib文件。有了這個,我可以在UIView上放置不同的按鈕,並使用delegate methods來處理它們。

然後我有一個MainViewController與一個頁眉和頁腳圖像,並在中間一個scrollView。我加載這樣的XIB文件。

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

把所有這些UIViewsNSArray和下一個地方他們scrollView內通過循環的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); 

所以我有以下classes

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

什麼,我的問題是現在,我怎麼能說我創建的UIViews(UIView * rootView)應該使用Page1的類。

+0

這是一個單一的事情,或者你可能想創建一個不同的'演示文稿'? – Wain

回答

0

在故事板中,您必須將Class更改爲自定義類。因此,例如在您的page1 XIB中,您必須轉到Identity Inspector(第3個選項卡),並在Class文本框中鍵入Page1,對於下一頁您必須再次執行此操作。在這種情況下,你可以打電話給rootView:

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

希望得到這個幫助。

相關問題