iOS:将NSObject类中soap webservice解析的值传递回UIViewController

iOS:将NSObject类中soap webservice解析的值传递回UIViewController,ios,xcode,web-services,soap,nsobject,Ios,Xcode,Web Services,Soap,Nsobject,我不知道为什么这么难,但我不能让它工作。这是我的简单问题: 我有一个UIViewController,它调用执行解析任务的NSObject类的paring类类型 我只需要将解析后的数据值返回到ViewController 有谁能为我提供一个简单的步骤或任何建议来做到这一点。。。 我真的需要为我的项目解决这个问题,最后期限快到了 谢谢 这是我的密码: ViewController.m @implementation ViewController - (void)viewDidLoad {

我不知道为什么这么难,但我不能让它工作。这是我的简单问题:

我有一个
UIViewController
,它调用执行解析任务的
NSObject
类的paring类类型

我只需要将解析后的数据值返回到
ViewController

有谁能为我提供一个简单的步骤或任何建议来做到这一点。。。 我真的需要为我的项目解决这个问题,最后期限快到了

谢谢 这是我的密码:

ViewController.m

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    wsClass *ws = [[wsClass alloc] init];
    [ws initParsing];
}
wsClass.h

@interface ProjListClass : NSObject

@property(nonatomic,strong) NSString * PROJECT_ID;
@property(nonatomic,strong) NSString * SHORT_DESCR;
@property(nonatomic,strong) NSString * LOCATION;
@end;

@interface wsClass : NSObject <NSXMLParserDelegate>{
ProjListClass *proj_obj;
ProjListClass *prj;

NSMutableData* webData;
NSMutableString *soapResults;
NSURLConnection *conn;

NSXMLParser *xmlParser;

}
@property(nonatomic,strong) NSMutableArray * arrHouses;
@property(nonatomic, strong)     NSXMLParser *xmlParser;

-(void) initParsing;
@end
@interface ProjListClass:NSObject
@属性(非原子,强)NSString*项目ID;
@属性(非原子,强)NSString*短描述;
@属性(非原子,强)NSString*位置;
@结束;
@接口wsClass:NSObject{
项目类别*proj_obj;
项目类别*prj;
NSMutableData*webData;
NSMutableString*soapResults;
NSURL连接*conn;
NSXMLParser*xmlParser;
}
@属性(非原子,强)NSMutableArray*arrHouses;
@属性(非原子,强)NSXMLParser*xmlParser;
-(无效)初始解析;
@结束
wsClass.m

#import "wsClass.h"

@implementation ProjListClass
@synthesize PROJECT_ID, SHORT_DESCR, LOCATION;
@end

@implementation wsClass

@synthesize arrHouses, xmlParser;

-(void) initParsing{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    soapResults = [[NSMutableString alloc] init];
    arrHouses=[[NSMutableArray alloc]init];

    NSString *soapMessage = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                         "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                         "<soap:Body>\n"
                         "<Projects_List xmlns=\"http://tempuri.org/\"/>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n"];
   NSURL *url = [NSURL URLWithString:@"http://192.168.0.10:8056/WServices.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/Projects_List" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

conn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( conn )
{
    webData = [NSMutableData data];
}
else
{
    NSLog(@"theConnection is NULL");
}   
}
....
....
....
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
   NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
    if (xmlParser)
  {
    xmlParser=nil;
  }
  xmlParser = [[NSXMLParser alloc] initWithData: webData];
  [xmlParser setDelegate: self];
  [xmlParser setShouldResolveExternalEntities:YES];
  [xmlParser parse];
 }

 ....
 ....
 ....
 -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
 namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
.....
.....
.....
 else if([elementName isEqualToString:@"ProjectsListDetails"])
{
    [arrHouses addObject:proj_obj];
    proj_obj=nil;
}

soapResults = nil;
soapResults = [[NSMutableString alloc]init];
}
#导入“wsClass.h”
@实现ProjListClass
@综合项目ID、简短描述、位置;
@结束
@wsClass的实现
@XML解析器;
-(void)初始化解析{
[UIApplication sharedApplication].networkActivityIndicatorVisible=是;
soapResults=[[NSMutableString alloc]init];
arrHouses=[[NSMutableArray alloc]init];
NSString*soapMessage=[NSString stringWithFormat:
@“\n”
“\n”
“\n”
“\n”
“\n”
“\n”];
NSURL*url=[NSURL URLWithString:@”http://192.168.0.10:8056/WServices.asmx"];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”];
[请求附加值:@”http://tempuri.org/Projects_ListforHTTPHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
conn=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
如果(康涅狄格州)
{
webData=[NSMutableData];
}
其他的
{
NSLog(@“连接为空”);
}   
}
....
....
....
-(无效)连接IDFinishLoading:(NSURLConnection*)连接
{
NSString*theXML=[[NSString alloc]initWithBytes:[webData可变字节]长度:[webData长度]编码:NSUTF8StringEncoding];
if(xmlParser)
{
xmlParser=nil;
}
xmlParser=[[NSXMLParser alloc]initWithData:webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:是];
[xmlParser parse];
}
....
....
....
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName
namespaceURI:(NSString*)namespaceURI限定名称:(NSString*)qName{
.....
.....
.....
else if([elementName IsequalString:@“ProjectsListDetails”])
{
[对象:proj_obj];
proj_obj=零;
}
soapResults=零;
soapResults=[[NSMutableString alloc]init];
}

您可以在NSObject类中创建协议,在所有解析操作完成后触发协议,并将视图控制器设置为代理。

请参阅下面的步骤

1)在NSOBject类中,比如说
ParsingModel
类,在进行解析的解析类中创建协议。随便你叫什么名字都行

   @protocol  WebServiceResponseDelegate <NSObject>

   @optional
  - (void)didRecieveResponseData:(NSMutableArray*)array;

  @end
只需要将解析后的数据发送到确认类,即从中创建解析对象

   //say didRecieveResponse this is the method called when you completed parsing of data

 // - (void)didRecieveResponse
  // {   
  //  if([delegate respondsToSelector:@selector(didRecieveResponseData)])
 //    {
  //    //pass populated dataSource which would have the Parsed Data.

  //    [delegate didRecieveResponseData:parsedData];
 //    //  parsedData is the NUMtableArray or any other DataSource.

  //}
编辑:下面是成功完成配对时调用的
委托
方法

  - (void)parserDidEndDocument:(NSXMLParser *)parser{
    //pass populated dataSource which would have the Parsed Data.  

    //before check whether that delegate method confirmed by the class.

    if([delegate respondsToSelector:@selector(didRecieveResponseData)])
     {
       [delegate didRecieveResponseData:parsedData];
     }

   //  parsedData is the NUMtableArray or any other DataSource.

   }
  // called when the parser has completed parsing. If this is encountered, the parse was successful.you need to call
2)并在确认类中,如您所说的
UIViewController
say
DataViewController
定义该委托方法 在您的
DataViewController.h
中,采用像这样的协议
DataViewController

并从创建解析模型类的位置设置
Delegate
像这样

  ParsingModel * paring = [ParsingModel alloc]init];
  [paring setWebServiceResponseDelegate:self];

 //definition of callback delegate method
 - (void)didRecieveResponseData:(NSMutableArray*)array
 {
 //here you would have the Parsed Data now you can use it as you want

 }

我希望您一切都清楚。

只需使用函数从该类返回值即可:-)谢谢Kamarshad,我已经编辑了我的线程并粘贴了我的代码,请查看一下并告诉我在代码中的更改位置。。。重新考虑我当前使用的代码,告诉我如何应用协议。@Mr.KLD查看我的编辑,更改代码。如果您仍然不理解,我将无法进一步帮助您。实际上,在S/O上,我们讨论逻辑,而不是提供完整的运行代码。以及我认为您在寻找完整的运行代码。男人只要看看代码,试着从中得到一些想法。
  ParsingModel * paring = [ParsingModel alloc]init];
  [paring setWebServiceResponseDelegate:self];

 //definition of callback delegate method
 - (void)didRecieveResponseData:(NSMutableArray*)array
 {
 //here you would have the Parsed Data now you can use it as you want

 }