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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:22:28  来源:igfitidea点击:

How to pass int Value from one view controller to next in iphone app

iphonexcode

提问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.hfile declare a propertyof type intwith var name mynumberlike this -

在你的NextViewController.h文件中声明一个property类型int为 var 名称的类型mynumber-

NextViewController.h

@property (nonatomic) int mynumber;

then synthesizeit in NextViewController.m

然后synthesize它在NextViewController.m

NextViewController.m

@synthesize mynumber;

now you can assignit as you are doing;

现在你可以assign做你想做的了;

回答by Rajneesh071

In NextViewControllermake 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.mcreate 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 类似。