0

所以我有一個帶有IBAction標題的按鈕,它的initWithNibName方法指向另一個ViewController。一切都嵌入在NavigationController中。initWithNibName:我沒有滾動和沒有導航欄?

我還創建了這個視圖控制器一個的.xib,這裏是一個快速截圖:

enter image description here

這裏是我的代碼:

.H

@interface ModeEmploiController : UIViewController 
{ 
    IBOutlet UIScrollView *scrollView; 
    UITextView *vueOffres, *vueInfos, *vueGrilles; 
} 

@property (nonatomic, retain) IBOutlet UIScrollView *scrollView; 

.M

@implementation ModeEmploiController 

@synthesize scrollView; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) 
    { 
     [scrollView setScrollEnabled:YES]; 
     [scrollView setContentSize:CGSizeMake(320, 529)]; 
     // Here I define vueOffres, vueInfos and vueGrilles and for each of them : 
     [self.view addSubview:vueGrilles/vueInfos/vueOffres]; 
    } 
} 

但是,當我運行我的應用程序,我的滾動未啓用,我沒有我的導航控制器的導航欄。發生了什麼?

+0

你如何初始化你的導航控制器? – Eimantas

+0

實際上,我只是添加了它,並將其嵌入到IB的視圖控制器中。 – Rob

回答

1

xib中刪除您的ModeEmploiController,但請保留子女ViewScrollView

現在點擊File's Owner並從右側面板的Identity inspector中放置ModeEmploiController

現在右鍵單擊File's Owner並將view的屬性連接到ViewscrollViewScrollView

+0

我試過了,它不啓用滾動。 – Rob

+0

是你的內容的尺寸實際上320,529?並且在ScrollView中看不到任何子視圖,是否以編程方式添加它? –

2

ScrollView內添加另一個視圖,我稱之爲礦山內容視圖。在你需要有一個uinavigation控制器,讓你的控制器導航控制器的RootViewController的導航欄做

self.scrollView.contentSize = self.contentView.frame.size; 

。像這樣

-(IBAction)MyButton:(id)sender 
{ 
    MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil]; 
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller]; 
    [self.navigationController presentModalViewController:navController animated:YES]; 
} 
1

您的初始化代碼是錯誤的方法。

由於您正在使用Storyboard,因此您的視圖控制器正在從nib文件中取消存檔。初始化控件的正確位置在awakeFromNib方法中。

確保您已經設置了一個IBOutlet屬性滾動視圖,並在故事板迷上它,然後:

- (void)awakeFromNib { 
    [self.scrollView setScrollEnabled:YES]; 
    [self.scrollView setContentSize:CGSizeMake(320, 529)]; 
    // Here I define vueOffres, vueInfos and vueGrilles and for each of them : 
    [self.view addSubview:vueGrilles/vueInfos/vueOffres]; 
} 

這只是留下您要添加的子視圖的問題。什麼是vueGrilles/vueInfos/vueOffres?您應該在viewDidLoad方法中正確創建此視圖,並將其添加爲子視圖,而不是在此初始化程序中。

+0

感謝您的建議,但它仍然不啓用滾動。 – Rob