xcode 如何在iphone应用程序中将int值从一个视图控制器传递到下一个
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12191767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass int Value from one view controller to next in iphone app
提问by Kiran Aftab
I want to send the myNumber values to the next controller in iphone app as normaaly do for NSString i am doing like this but it is not working
我想将 myNumber 值发送到 iphone 应用程序中的下一个控制器,就像通常为 NSString 所做的那样,我正在这样做,但它不起作用
int mynumber=100;
NextViewController*targetController=[[NextViewController alloc]init];
targetController.mynumber=mynumber;
[self.navigationController pushViewController animated:YES];
NextViewController
下一个视图控制器
int mynumber;
Implementation NextViewController
实现 NextViewController
int mydata=mynumber;
回答by saadnib
In you NextViewController.h
file declare a property
of type int
with var name mynumber
like this -
在你的NextViewController.h
文件中声明一个property
类型int
为 var 名称的类型mynumber
-
NextViewController.h
@property (nonatomic) int mynumber;
then synthesize
it in NextViewController.m
然后synthesize
它在NextViewController.m
NextViewController.m
@synthesize mynumber;
now you can assign
it as you are doing;
现在你可以assign
做你想做的了;
回答by Rajneesh071
In NextViewController
make property of integer and synthesize it.
在NextViewController
整数的 make 属性中并合成它。
@property(nonatomic) NSInteger mynumber;
@synthesize mynumber;
then
然后
int mynumber=100;
NextViewController *targetController=[[NextViewController alloc]init];
targetController.mynumber=mynumber;
[self.navigationController pushViewController:targetController animated:YES];
回答by iForests
You need to set the property in NextViewController.h first:
您需要先在 NextViewController.h 中设置属性:
@property NSInteger mynumber;
And in NextViewController.m:
在 NextViewController.m 中:
@synthesize mynumber;
Your code will work after these steps.
您的代码将在这些步骤后工作。
回答by user3073411
@property NSInteger mynumber;
@property NSInteger mynumber;
And in NextViewController.m:
在 NextViewController.m 中:
@synthesize mynumber;
@synthesize mynumber;
work very good
工作很好
回答by IronManGill
I your AppDelegate.m
create int dataString;
as a global variable. Now use it to pass data from one View to another by adding your code to your firstView like int FirstViewData = dataString;
Now Call it in your Second View similarly.
我AppDelegate.m
创建int dataString;
为全局变量。现在使用它通过将代码添加到您的 firstView 来将数据从一个 View 传递到另一个 View,就像int FirstViewData = dataString;
Now Call it in your Second View 类似。