如何制作进入不同屏幕的按钮? [英] How to make buttons that go to a different screen?

查看:166
本文介绍了如何制作进入不同屏幕的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我对这个想法有很多麻烦.如何在按钮上使按钮转到其他屏幕?

Hey I'm having a lot of trouble with this idea I have. How do I make buttons that go to a different screen but on the CODE?

基本上取决于每个用户的值(可以说该值已经在x中),每个用户可能会有所不同,这会产生一个按钮列表...

Basically depending on a value that may or may not be different for every user (Let's say the value is in x already) it will make a list of buttons...

当您单击按钮列表时,它们各自分别进入不同的屏幕.

When you click the list of buttons, they each individually go to a different screen.

我该怎么做?我知道如何在情节提要上..但是代码明智吗?

How do I do this? I know how to on storyboard.. but code wise?

我应该注意,对于按钮,我确实有此功能,并且它在代码中有效(未使用情节提要):

I SHOULD note that for the buttons specifically I have this and it is working in the code (didn't use storyboard):

        UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake(50, 200, 200, 50);
        [btn setTitle:@"Button 1" forState:UIControlStateNormal];
        [self.view addSubview:btn];

推荐答案

您可以通过执行以下操作将操作附加到按钮上:

You can attach an action to your button by doing the following:

UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(50, 200, 200, 50);
[btn setTitle:@"Button 1" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(someAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];

,然后在someAction方法中,以模态方式或通过导航控制器推送视图

and then in your someAction method, you push the view modally or via your navigation controller

- (void)someAction
{
    //init your view controller here....
    YourViewController *vc = [[YourViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

这篇关于如何制作进入不同屏幕的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆