2011-05-09 104 views
1

嘿家伙我是一个可可的新手开发人员,我试图创建一个简单的应用程序。其中显示4个不同的页面,您可以通过标签栏进行选择。(Xcode)UIButtons和页面之间的链接

我的问题:我在IB的First/Home页面(==> FirstView.xib)上做了一个UIButton,我尝试将它链接到我的第二页(==> SecondView.xib)互联网。

事情是,我可以建立我的代码,但没有反应,当我尝试点击我的按钮,你能帮我吗?

代码FirstView.h:

#import <UIKit/UIKit.h> 


@interface FirstViewController : UIViewController { 

UIButton *button;} 

@property (nonatomic, retain) IBOutlet UIButton *button; 

- (IBAction)goToViewTwo; 

@end 

代码FirstView.m: @implementation FirstViewController @synthesize按钮;

- (IBAction)goToViewTwo { 
SecondViewController *SecondView= [[SecondViewController alloc] initWithNibName: @"SecondView" bundle:[NSBundle mainBundle]]; 
[self.navigationController pushViewController:SecondView animated:YES]; 
} 

- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)dealloc { 
    [super dealloc]; 
    [button release]; 
} 

@end 

关于在FIrstVIew.xib网点:

我联系 “润色内” 向 “goToViewTwo” 和 “b^utton” 到“文件拥有者”

回答

0

我在印象中这是在一个标签栏中,每个标签栏按钮显示一个.xib文件,如果是这种情况,解决方案非常简单,你的tabBarController管理视图控制器数组中的视图。 IBAction方法应该如下:

- (IBAction)goToViewTwo { 
    self.tabBarController.selectedIndex = 1; 
} 

这告诉你的标签栏控制器从当前视图控制器切换(位于索引0)到第二(在索引1)

+0

圣小号*** ^^,非常感谢你(觉得如此愚蠢现在:o)它工作正常:) – Nicolas 2011-05-09 20:17:25

+0

我的荣幸,男人。虽然没有必要感到愚蠢。随着时间的推移,你会发现一些有用的东西。一个被接受的答案将不胜感激,虽然=] – justin 2011-05-09 20:33:20