2013-05-10 82 views
0

我使用textfield输入我的web服务的字段。例如,我输入了StationID textfield = 35016。如何使用搜索栏输入文本和过滤器进行选择?

我有770个StationID,每个站都有一个名称。 stationId 35016的名称是New Istanbul LTD STI.I当我进入New搜索栏时,它必须列出给我新的Istanbul LTD.STI.Than,然后我会选择发送Web服务呼叫。

我该如何做搜索和选择搜索field.This代码Textfield.How更改为搜索栏?谢谢。

在.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; 

} 

回答

1

你必须使用的UISearchBar控制及其委托的方法.h文件中

#import <UIKit/UIKit.h> 

    @interface AMDViewController : UIViewController<UITextFieldDelegate,NSXMLParserDelegate> 

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

    @end 

。 这里是一个可以帮助你

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

+0

这是搜索和显示table.I想从texfield – Mhmt 2013-05-10 12:56:54

+0

可以使用编辑Changed事件或编辑开始事件的web服务搜索的链接。在这些事件中添加您的搜索查询代码 – 2013-05-10 13:13:34

+0

@ Jay Gajjar您能告诉我任何样本吗?我不知道如何使用。 – Mhmt 2013-05-10 13:16:29

相关问题