Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在类之间共享数据_Iphone_Web Services_Web Applications_Mobile Website - Fatal编程技术网

Iphone 在类之间共享数据

Iphone 在类之间共享数据,iphone,web-services,web-applications,mobile-website,Iphone,Web Services,Web Applications,Mobile Website,我正在构建一个iphone应用程序,它尝试使用web服务获取数据。用户单击按钮将导航到一个新视图。 登录操作的代码是 - (IBAction)btnLoginAction:(id)sender { [UIApplication sharedApplication].networkActivityIndicatorVisible=YES; activityIndicator=[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(

我正在构建一个iphone应用程序,它尝试使用web服务获取数据。用户单击按钮将导航到一个新视图。 登录操作的代码是

- (IBAction)btnLoginAction:(id)sender 
{

 [UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
 activityIndicator=[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(50.0, 50.0, 50, 50)];
 [activityIndicator setCenter:CGPointMake(156, 208)];
 [activityIndicator startAnimating];

 [self.view addSubview:activityIndicator];
 soapMessenger=[[SoapMessenger alloc] init];
 parser=[[XML_Parsing alloc] init];
 [soapMessenger buildSoap:@"CURRENT"];
 [soapMessenger setConnection];

其中soapMessenger和xml_解析是用于创建连接和解析数据的类…我能够解析xml。但问题是将该数据传递给新的视图控制器…如何将结果数据传递给新的类

这是一个模型-视图-控制器问题。MVC。数据类应该将数据存储在模型中,然后模型的相关部分可以传递给新类-通常通过在新类中合成正确类型的属性,然后alloc/init新类,并设置属性。

您需要定义一个模型类,该模型类保存从XML解析的数据,然后通过属性传递给新的视图控制器。

如果要将数据从一个类传递到另一个类,则需要在传递数据的类中创建要传递的数据类型的属性

范例

FirstVC—您希望从中将值传递给下一个视图控制器的类

SecondVC—要将值传递给的第二个类

@interface FirstVC : UIViewController{
NSInteger *testInteger;
}

@implementation FirstVC{

- (IBAction)btnLoginAction:(id)sender 
{
SecondVC *second = [[SecondVC alloc] initWithNibName:@"SecondVC" buddle:[NSBundle mainbundle]];
second.receivingInteger=testInteger;
[second release];
}

}

@interface SecondVC{
NSInteger receivingInteger;
}
@property(nonatomic) NSInteger receivingInteger;

我已经弄明白了…我使用了协议来实现它。

答案是否有用?我已经完全做到了。我定义了一个方法来检索解析结果。我在ConnectionIDFinishLoadIG方法中获得解析结果…我正在使用属性来设置此方法中变量的值…但是当我导航到下一个视图时,该值未得到更新。