从一个UIView传递整数值到另一个UIview [英] passing integer value from one UIView to another UIview

查看:76
本文介绍了从一个UIView传递整数值到另一个UIview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个代码,我想将一个uiview的整数值传递给另一个视图.在另一个uiview中,该整数值作为label的文本.如何为此编写代码?

I am creating a code in which i want to pass integer value for one uiview to another view.In another uiview that integer value so as text of label.How make code for that?

推荐答案

将其放在SecondViewController的.h文件中

Take this in .h file in SecondViewController

int value;

在SecondViewController中实现以下功能

Make below function in SecondViewController

-(void)setValue:(int)number{
    value=number;
}

现在在第一"视图控制器中执行以下操作:

Now In First view controller do like this:

ParentViewController *objSecond = [[ParentViewController] initwithNibName:@"parentView.xib" bundle:nil];

[objSecond setValue:15]; // Pass actual Value here
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];

现在,在secondViewController viewWillAppear方法中编写此代码.

Now, In secondViewController viewWillAppear Method write this.

-(void)viewWillAppear:(BOOL)animated{
      myValue = value;
}

请在我手写时检查拼写错误.希望有帮助.

Please check spelling mistakes as I hand written this. Hope this help.

如果您不使用navigationContoller,则可以执行以下操作.

If you are not using navigationContoller then you can do something like this.

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
[objSecond setValue:15]; // Pass actual Value here
[objSecond viewWillAppear:YES];
[self.view addSubview:objSecond];
[objSecond release];

这篇关于从一个UIView传递整数值到另一个UIview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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