从一个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];