我不知道爲什麼這很困難,但我無法得到它的工作。這是我的簡單問題:iOS:從NSObject類中的soap webservice傳遞解析值到UIViewController
我有一個UIViewController
調用配對類類,執行解析工作。
我只需要將解析的數據值返回到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
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];
}
Just Simple使用函數返回該類的值:-) – 2013-05-03 11:52:27