No but maybe yes.
I know I would call it there, just to remove old items before new search brings anything. Then later in NSURLConnectionDelegate again to populate the table with the fresh data.
In my own project I have a search bar, but I am displayng data already in memory so I reload table after each key press. If you're dealing with responsive server and if you have enough time to do some experiments you can try comunicating with the server in -searchBar:textDidChange: just for fun of it.
sorry i got confused with the command.
my app has a lot of spaghetti programming, its really sloppy, but I'm just trying to get it work, and clean it up later.
but basically I'm just trying to populate my search bar view, and I'm just using the same code basically that i used before (which was also a table view) to populate my search bar tableview (search results) but before it only returned one item, but now since it a search function, it returns more than one parsed item, does this matter? does it conflict?
im definitely getting data back from the web service, as i checked in my debugger, its just not populating my tableview.
heres my code, and if u want to and have the time, can u tell me whats wrong? i get a bad EXC_BAD_ACCESS error on this part of the code
Code:
searchData.searchCode = [NSMutableString stringWithString:searchViewItemNo];
i also used a class and an array, because i have no idea how to count all my search results without them.
Code:
- (void)parseXML
{
GlobalStrings* theDataObject = [self theGlobalClass];
NSLog (@"parseXML");
// Initialize the parser with our NSData from the RSS feed
NSXMLParser *xmlParser = [[NSXMLParser alloc]
initWithData:self.responseData];
// Set the delegate to self
[xmlParser setDelegate:self];
// Start the parser
if (![xmlParser parse])
{
NSLog (@"An error occurred in the parsing");
}
// Release the parser because we are done with it
[xmlParser release];
Searches *searchData = [[Searches alloc] init];
searchData.searchCode = [NSMutableString stringWithString:searchViewItemNo];
searchData.searchDescript = [NSMutableString stringWithString:searchViewDescript];
searchData.searchOnHand = [NSMutableString stringWithString:searchViewOnHand];
searchData.searchPrice = [NSMutableString stringWithString:searchViewPrice];
[theDataObject.searchTableArray addObject:searchData];
}
added this just to make sure its fine (it worked on my other view controllers, but just to be safe)
Code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog (@"didEndElement");
// Check to see which element we have ended
// If we are in an item and ended a title
if ([elementName isEqualToString:@"onhand"])
{
searchViewOnHand = capturedCharacters ;
NSLog(@" onhand = %@", capturedCharacters);
}
if ([elementName isEqualToString:@"description"])
{
searchViewDescript = capturedCharacters;
NSLog(@" descpt = %@", capturedCharacters);
}
if ([elementName isEqualToString:@"price"])
{
searchViewPrice = capturedCharacters;
}
if ([elementName isEqualToString:@"itemno"])
{
searchViewItemNo = capturedCharacters;
}
[capturedCharacters release];
capturedCharacters = nil;
if ([elementName isEqualToString:@"smartsearch"]) {
// We are no longer in an item element
inItemElement = NO;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (capturedCharacters != nil)
{
[capturedCharacters appendString:string];
}
}
and heres how i set up my table
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
GlobalStrings* theDataObject = [self theGlobalClass];
// Return the number of rows in the section.
return [theDataObject.searchTableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GlobalStrings* theDataObject = [self theGlobalClass];
static NSString *CellIdentifier = @"SearchCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
Searches *mySearch = [Searches alloc];
mySearch = [theDataObject.searchTableArray objectAtIndex:[indexPath row]];
UILabel *itemLabel = (UILabel *) [cell viewWithTag:100];
itemLabel.text = mySearch.searchCode;
UILabel *descriptLabel = (UILabel *) [cell viewWithTag:101];
descriptLabel.text = mySearch.searchDescript;
UILabel *onHandLabel = (UILabel *) [cell viewWithTag:102];
onHandLabel.text = mySearch.searchOnHand;
UILabel *priceLabel = (UILabel *) [cell viewWithTag:103];
priceLabel.text = mySearch.searchPrice;
UIImageView *searchImageView = (UIImageView *) [cell viewWithTag:104];
NSString *sURL = [[NSString alloc] initWithString:[NSString stringWithFormat:@"http://***************.com:90/prodimage/%@_t.jpg", searchViewItemNo]];
NSData *myData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", sURL]]];
UIImage *picture = [[UIImage alloc] initWithData:myData];
[searchImageView setImage:picture];
[searchImageView setNeedsDisplay];
return cell;
}
i know its a lot of coding, but any quick insight, or anything that catches ur eye at first glimpse would be much appreciated.