2014-02-19 63 views
1

嗨,我可以問我是否可以混合xib與故事板中的我的UIViewController?就像他們在他們的文件所有者中共享一個控制器一樣,因爲我打算通過使用nib作爲expandedview來創建可展開的視圖,並且我想將一個值從nib文件傳遞到故事板中的UIViewController。謝謝。UIViewController在與nib文件的故事板

回答

3

我不建議你從故事板混合廈門國際銀行和視圖控制器和他們掛鉤全部一起。 如果你想爲一個擴展視圖中添加一個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]; 

我希望我理解正確你。

+0

謝謝Idan我明白了你的觀點,但我怎麼能觸摸我的筆尖的元素?例如,我想更改我的筆尖UILabel – RonPelayo

+0

好的,我編輯了我的答案,請檢查。 :-) –

0

在故事板,你不提供xibs,但如果你想使用它們從筆尖加載然後使用:

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

更好地使用「awakeAfterUsingCoder」 –