簡體   English   中英

帶有Nib文件的情節提要中的UIViewController

[英]UIViewController in storyboard with nib file

嗨,我可以問我是否可以將xib與故事板中的UIViewController混合使用嗎? 就像他們在文件所有者中共享一個控制器一樣,因為我計划通過使用nib作為expandview創建一個可擴展視圖,並且我想將nib文件中的值傳遞給Storyboard中的UIViewController 謝謝。

我不建議您混合使用xib和情節提要中的View Controller並將它們掛在一起。 如果要將UIView作為擴展視圖添加到視圖控制器,則可以執行以下操作:

// Load the first view inside our xib from main bundle
UIView *view = [[NSBundle mainBundle] loadNibNamed:@"nib_name" owner:self options:nil][0];

// Define new X,Y to our view
float new_x_position = 0;
float new_y_position = 400;
view.frame = CGRectMake(new_x_position, new_y_position, CGRectGetWidth(view.frame), CGRectGetHeight(view.frame));

// UILabel inside our nib, '111' is the tag we set to our UILabel
UILabel *label = (UILabel*)[view viewWithTag:111];

// Add our view to the current view as a sub view
[self.view addSubview:view];

我希望我能正確理解你。

在情節提要中,沒有為您提供xibs,但如果要使用它們從nib加載,請使用:

MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"CustomDownloadedXib" bundle:nil];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM