2014-01-14 74 views
0

我正在使用标签栏导航/我是一个新手。更新UILabel,UIbutton从第一个视图控制器导入的第二个视图控制器

我有ViewController1它具有所有IBOutlet UILabel,UIButton和一些IBAction功能。我想将所有这些数据传递给ViewController2。

这是我尝试的: 我注意到在ViewController2中使用后:#import“Viewcontroller1.h” - 所有这些函数/插座都可以在Main.storyboard上使用。我开始将这些插座连接到Main.storyboard上的ViewController2,它们似乎在第一次加载时工作。但是,当我与Viewcontroller1交互并更改UILabels时,这些将不会在Viewcontroller2上更新。任何帮助是极大的赞赏!!

问候,

马特

回答

0

你必须定义不同的IBOutlets和IBActions在其各自的.h文件中的每个视图控制器,并在其各自的.m文件执行。

假设您有两个视图控制器,每个视图控制器上都有一个名为“Back”的按钮,位置完全相同,功能完全相同。然后,您必须按以下方式定义您的IBOutlet和IBAction:

@interface ViewController1 

@property(nonatomic, assign) IBOutlet UIButton *backButton; 

-(IBAction)on_back:(id)sender; 

@end 

@implementation ViewController1 

-(IBAction)on_back:(id)sender 
{ 
    //your code for doing back action... 
} 
@end 

//similarly as above you'll have to write once 
//more in @interface and @implementation of ViewController2. 
//Once done, you can bind the respective IBOutlets and IBAction 
//from Storyboard or XIB/Nib file. 
相关问题