嘿伙计我是可可的新手开发者,我正在尝试创建一个简单的应用程序。它显示4个不同的页面,您可以通过选项卡栏进行选择。
我的问题:我在IB的第一页/主页(==> 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中的商店:
我将“Touch Up Inside”与“goToViewTwo”和“b ^ utton”链接到“文件所有者”
答案 0 :(得分:0)
我认为这是在标签栏中,每个标签栏按钮显示.xib文件。如果是这种情况,解决方案相当简单。 tabBarController管理视图控制器数组中的视图。要在它们之间切换,您的IBAction方法应如下:
- (IBAction)goToViewTwo {
self.tabBarController.selectedIndex = 1;
}
这告诉标签栏控制器从当前视图控制器(索引0)切换到第二个(索引1)