gpt4 book ai didi

ios - 按下按钮后传递参数以在 IOS 中查看

转载 作者:行者123 更新时间:2023-11-29 11:09:15 25 4
gpt4 key购买 nike

我是 IOS 编程的新手。到目前为止,我一直在用android编程。所以在 android 中,当按下按钮时传递参数的代码将是这样的:

Intent i = new Intent(MainScreen.this,OtherScreen.class);
Bundle b = new Bundle();
b.putString("data_1",data);
i.putExtras(b);
startActivity(i);

在打开的事件上,我会这样写:

Bundle b = getIntent().getExtras();
ski_center=b.getString("data_1");

我需要在IOS的MainScreen和OtherScreen中改变什么方法才能实现上述。

基本上我将有 3 个按钮,比如说在我的 MainScreen 中,每个按钮都会打开 Otherview,但每次都会传递不同的参数。

每个按钮的敌人示例我在 MainScreen.m 中都有这样的代码

@synthesize fl;
-(IBAction) ifl:(id) sender {
}

所以我也需要你的帮助来确定“缺失”代码的放置位置。

最佳答案

像 Java 中的属性一样为您的 UIViewController(Android 的 Activity)声明一个 iVar。

在MainViewController.m中

OtherUIViewController * contr = [[OtherUIViewController alloc] initWithNibname...];
contr.data = yourData;

已编辑:添加完整代码...

Intent i = new Intent(MainScreen.this,OtherScreen.class);Bundle b = new Bundle();b.putString("data_1",data);

这里的 MainScreen 是调用代码,现在在 iOS 中它将是 MainUIViewcontroller

  • 像这样创建一个 OtherUIViewController:

OtherUIViewController.h

@interface OtherUIViewController : UIViewController
{
NSData* data;
}
@property (strong, nonatomic) NSData* data;

在 OtherUIViewController.m 中

@implementation OtherUIViewController.m
@synthetize data;

// override
- (void)viewDidLoad
{
[super viewDidLoad];
// do something with data here
}

要具有 3 种不同的行为,数据可以是 int 或 NSString。在 - (void)viewDidLoad 中,您将检查 data 值并执行 3 项差异操作。

希望对你有帮助

关于ios - 按下按钮后传递参数以在 IOS 中查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12253626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com