Mhmt
Mhmt

Reputation: 769

How to use Search Bar for enter text and filter for selection?

I use textfield for enter field of my web service.For example I entered StationID textfield=35016.

I have total 770 StationID and every station have a name. stationId 35016 name is New Istanbul LTD STI.I want when I entered New to search bar it must will list to me New Istanbul LTD.STI.Than I will select for sending web service call.

How can I do for search and select searching field.This code for Textfield.How to change for search bar ? Thank you.

in .h file

   #import <UIKit/UIKit.h>

   @interface AMDViewController :  UIViewController<UITextFieldDelegate,NSXMLParserDelegate>

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

  @end

in .m file

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;

}

Upvotes: 0

Views: 276

Answers (1)

Jay Gajjar
Jay Gajjar

Reputation: 2741

You have to use uisearchbar control and its delegate methods. Here is the link that may help you

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

Upvotes: 1

Related Questions