Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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中的表视图上加载Soap响应_Iphone_Ios_Ios4_Ios 4.2 - Fatal编程技术网

如何在iphone中的表视图上加载Soap响应

如何在iphone中的表视图上加载Soap响应,iphone,ios,ios4,ios-4.2,Iphone,Ios,Ios4,Ios 4.2,我正在处理soap请求和响应。。我可以发出服务器请求,也可以得到服务器响应,这是我在uialertview消息上解析的,但是当我试图将其加载到选项卡视图时,我无法用字符串填充数组,因此请帮助我 下面是我的代码 #import "SoapTableViewController.h" @implementation SoapTableViewController @synthesize customerArray; @synthesize webData; @synthesize dict;

我正在处理soap请求和响应。。我可以发出服务器请求,也可以得到服务器响应,这是我在uialertview消息上解析的,但是当我试图将其加载到选项卡视图时,我无法用字符串填充数组,因此请帮助我

下面是我的代码

#import "SoapTableViewController.h"


@implementation SoapTableViewController

@synthesize customerArray;
@synthesize webData;
@synthesize dict;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}


-(void) GetCustomers
{
    NSString *soapMessage =@"<?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"
    "<GetCustomers xmlns=\"http://www.fashionize.ca/\" />\n"
    "</soap:Body>\n"
    "</soap:Envelope>\n";       

    NSURL *url = [NSURL URLWithString:@"http://www.fashionize.ca/Service1.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://www.fashionize.ca/GetCustomers" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if( theConnection )
    {
        webData = [[NSMutableData data] retain];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }
}



-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response 
{
    webData =[[NSMutableData data]retain];
    [webData setLength: 0];
}


-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data
{
    [webData appendData:data];
}

-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error
{
    NSLog(@"Error With Connection");
    [webData release];
    [connection release];
}

-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] 
                        initWithBytes: [webData mutableBytes] 
                        length:[webData length] 
                        encoding:NSUTF8StringEncoding];
    //---shows the XML---
    NSLog(theXML);
   // [self parseXml:theXML];
    [theXML release];  


       if (xmlParser)
        {
            [xmlParser release];
        }    
        xmlParser = [[NSXMLParser alloc] initWithData: webData];
        [xmlParser setDelegate: self];
        [xmlParser setShouldResolveExternalEntities:YES];
        [xmlParser parse];

    [connection release];
    [webData release];
}

-(void) parser:(NSXMLParser *) parser 
didStartElement:(NSString *) elementName 
  namespaceURI:(NSString *) namespaceURI 
 qualifiedName:(NSString *) qName
    attributes:(NSDictionary *) attributeDict {

    if( [elementName isEqualToString:@"Name"])
    {
        if (!soapResults)
        {
            soapResults = [[NSMutableString alloc] init];
                     }
        elementFound = YES;
    }
}

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
    if (elementFound)
    {
        [soapResults appendString: string];

        [customerArray addObject:soapResults];

    }
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI 
qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"Name"])
    {

        //---displays the country---
                [customerArray addObject:soapResults];
        NSLog(soapResults);        
        elementFound = FALSE;
        UIAlertView *alert = [[UIAlertView alloc] 
                              initWithTitle:@"Customer Name!" 


                              message:soapResults 
                              delegate:self  
                              cancelButtonTitle:@"OK" 
                              otherButtonTitles:nil];
        [alert show];
        [alert release];
        [soapResults setString:@""];
        elementFound = FALSE; 


        //[customerArray addObject:soapResults];


    }
}

- (void)dealloc
{
    [webData release];
    [customerArray release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self GetCustomers];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [customerArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    NSUInteger row = [indexPath row];
    cell.textLabel.text =[customerArray objectAtIndex:row];
    // Configure the cell...

    return cell;
}
#导入“SoapTableViewController.h”
@SoapTableViewController的实现
@综合客户关系;
@综合网络数据;
@合成dict;
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:style];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)获取客户
{
NSString*soapMessage=@“\n”
“\n”
“\n”
“\n”
“\n”
“\n”;
NSURL*url=[NSURL URLWithString:@”http://www.fashionize.ca/Service1.asmx"];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”];
[请求附加值:@”http://www.fashionize.ca/GetCustomersforHTTPHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
if(连接)
{
webData=[[NSMutableData]保留];
}
其他的
{
NSLog(@“连接为空”);
}
}
-(void)连接:(NSURLConnection*)连接DidReceiverResponse:(NSURResponse*)响应
{
webData=[[NSMutableData]保留];
[webData setLength:0];
}
-(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据
{
[webData:data];
}
-(无效)连接:(NSURLConnection*)连接失败错误:(NSError*)错误
{
NSLog(@“连接错误”);
[网络数据发布];
[连接释放];
}
-(无效)连接IDFinishLoading:(NSURLConnection*)连接{
NSLog(@“完成。收到的字节数:%d”,[webData长度];
NSString*theXML=[[NSString alloc]
initWithBytes:[webData可变字节]
长度:[webData长度]
编码:NSUTF8StringEncoding];
//---显示XML---
NSLog(theXML);
//[self-parseXml:theXML];
[XML发布];
if(xmlParser)
{
[xmlParser release];
}    
xmlParser=[[NSXMLParser alloc]initWithData:webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:是];
[xmlParser parse];
[连接释放];
[网络数据发布];
}
-(void)解析器:(NSXMLParser*)解析器
didStartElement:(NSString*)元素名称
namespaceURI:(NSString*)namespaceURI
限定名称:(NSString*)qName
属性:(NSDictionary*)属性指令{
if([elementName IsequalString:@“Name”])
{
如果(!soapResults)
{
soapResults=[[NSMutableString alloc]init];
}
elementFound=是;
}
}
-(void)解析器:(NSXMLParser*)解析器查找字符:(NSString*)字符串
{
if(elementFound)
{
[soapResults appendString:string];
[customerArray添加对象:soapResults];
}
}
-(void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI
限定名称:(NSString*)qName
{
if([elementName IsequalString:@“Name”])
{
//---显示国家---
[customerArray添加对象:soapResults];
NSLog(soapResults);
elementFound=FALSE;
UIAlertView*警报=[[UIAlertView alloc]
initWithTitle:@“客户名称!”
信息:soapResults
代表:赛尔夫
取消按钮:@“确定”
其他按钮:无];
[警报显示];
[警报发布];
[soapResults集合字符串:@”“;
elementFound=FALSE;
//[customerArray添加对象:soapResults];
}
}
-(无效)解除锁定
{
[网络数据发布];
[客户阵列释放];
[super dealoc];
}
-(无效)未收到记忆警告
{
//如果视图没有superview,则释放该视图。
[超级记忆警告];
//释放所有未使用的缓存数据、图像等。
}
#pragma标记-视图生命周期
-(无效)viewDidLoad
{
[超级视图下载];
[自助客户];
//取消对下一行的注释以保留演示文稿之间的选择。
//self.clearselectiononviewwillappear=否;
//取消对以下行的注释,以在此视图控制器的导航栏中显示编辑按钮。
//self.navigationItem.rightBarButtonItem=self.editButtonItem;
}
-(无效)视图卸载
{
[超级视频下载];
//释放主视图的所有保留子视图。
//例如,self.myOutlet=nil;
}
-(无效)视图将显示:(BOOL)动画
{
[超级视图将显示:动画];
}
-(无效)视图显示:(BOOL)动画
{
[超级视图显示:动画];
}
-(无效)视图将消失:(BOOL)已设置动画
{
[超级视图将消失:动画];
}
-(无效)视图消失:(BOOL)已设置动画
{
[超级视窗消失:动画];
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
//对于支持的方向返回YES
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
#pragma标记-表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
#警告:方法实现可能不完整。
//返回节数。
返回1;
}
-(NSInteger)表视图:(UITableView)
customerArray = [[NSMutableArray alloc]initWithCapacity:0];
-(void)parserDidEndDocument:(NSXMLParser *)parser{
[reload tblView];
}