0

我使用文本字段作为我的 Web 服务的输入字段。例如,我输入了 StationID 文本字段 = 35016。

我总共有 770 个 StationID,每个站都有一个名称。stationId 35016 名称是 New Istanbul LTD STI。我想当我输入 New 到搜索栏时,它必须向我列出 New Istanbul LTD.STI。然后我将选择发送 Web 服务调用。

如何进行搜索并选择搜索字段。Textfield 的此代码。如何更改搜索栏?谢谢你。

在 .h 文件中

   #import <UIKit/UIKit.h>

   @interface AMDViewController :  UIViewController<UITextFieldDelegate,NSXMLParserDelegate>

  @property (unsafe_unretained, nonatomic) IBOutlet UITextField *StationID;

  @end

在 .m 文件中

enter code here

#import "AMDViewController.h"

@interface AMDViewController ()
{  
NSMutableData *webData;
NSXMLParser *xmlParser;
NSMutableString *retornoSOAP;
BOOL teveRetorno;


@end

@implementation AMDViewController

@synthesize StationID;

}



      -(IBAction)calcularTemperatura:(UIButton *)sender{


    NSString *mensagemSOAP= [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"
     "<Details xmlns=\"http://tempuri.org/\">\n"
                         "<StationID>%@</StationID>\n"
                        "<StationName>%@</StationName>\n" //StationName is here in web sevrice
                         "</Details>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n",StaionID.text];


NSLog(@"SOAP msg = \n%@\n\n", mensagemSOAP);

NSURL *url = [NSURL URLWithString:@"http://webservice/sample.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];    NSString *tamanhoMensagem = [NSString stringWithFormat:@"%d", [mensagemSOAP length]];

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

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

if(conexao){
    webData = [NSMutableData data];
}else{
    NSLog(@"Connection Error.");
}
}

 -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ( [elementName isEqualToString:@"StationID"] ) {
    if (!retornoSOAP) {
        retornoSOAP = [[NSMutableString alloc] init];
    }
    teveRetorno = YES;
}

 }

-  (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName{



 if ( [elementName isEqualToString:@"StationID"] ) {
    StaionTotalSalesTodayLabel.text = retornoSOAP;
    retornoSOAP = nil;
    teveRetorno = NO;

}
4

1 回答 1

1

您必须使用 uisearchbar 控件及其委托方法。这是可以帮助您的链接

http://www.youtube.com/watch?v=P2yaZXn4MU0

于 2013-05-10T12:46:44.373 回答