【问题标题】:(Xcode) Links Between UIButtons and pages(Xcode) UIButtons 和页面之间的链接
【发布时间】:2011-08-21 21:53:15
【问题描述】:

大家好,我是 cocoa 的新手开发人员,我正在尝试创建一个简单的应用程序。它显示了 4 个不同的页面,您可以通过标签栏选择它们。

我的问题:我使用 IB 在第一页/主页 (==>FirstView.xib) 上创建了一个 UIButton,并尝试使用在网。

问题是我可以构建我的代码,但是当我尝试点击我的按钮时没有任何反应,你能帮帮我吗?

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 中的 outlets

我将“Touch Up Inside”链接到“goToViewTwo”,将“b^utton”链接到“File's Owner”

【问题讨论】:

    标签: cocoa-touch xcode ios uibutton


    【解决方案1】:

    我的印象是这是在一个标签栏中,每个标签栏按钮都显示一个 .xib 文件。如果是这种情况,解决方案相当简单。您的 tabBarController 在一组视图控制器中管理您的视图。要在它们之间切换,您的 IBAction 方法应如下所示:

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

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

    【讨论】:

    • 天哪 ^^ ,非常感谢(现在感觉很愚蠢:o)它工作正常 :)
    • 我的荣幸,伙计。不过,没必要感到愚蠢。随着时间的推移,你会发现一堆有用的东西。一个被接受的答案将不胜感激,尽管 =]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2022-08-03
    • 2013-01-30
    • 2014-05-31
    • 2022-01-18
    相关资源
    最近更新 更多