 |
 |
|
 |
03-11-2009, 09:20 AM
|
#1 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 35
|
ReloadData in UITableView after Searh
Im using a tableView and a searchBar.
When the user writes a word and hit the search button,
this method:
Code:
- (void) searchBarSearchButtonClicked:(UISearchBar *)SearchBar
{
// 1:
passedString = searchBar.text;
// 2:
[self.tableView reloadData];
}
1: Sets the search text in a global string who changing URL to the XML database. Witch working just fine.
2: Should reload the data in the tableView after the searching text.
There is nothing wrong with the database xml parsing, because it works when u type in a search word in the code your self. But it wont reload the taleView Data?
Im a noob so please help :]
|
|
|
03-11-2009, 09:52 AM
|
#2 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 35
|
..
Last edited by lajloos; 03-11-2009 at 11:54 AM.
|
|
|
03-11-2009, 10:06 AM
|
#3 (permalink)
|
|
New Member
Join Date: Jan 2009
Posts: 77
|
Is the delegate and datasource on your tableview set and methods properly implemented??
If so you should be able to set a breakpoint in
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
and see what is happening when you call reloadData.
|
|
|
03-11-2009, 10:58 AM
|
#4 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 35
|
Well yes i think the delegate and datasource is right.
I tried breakpoint first on the method u sent me and then on the searchButton method. But i dont really understand what to do. It dont seems to be anything wrong.
Is there any other better way to do this?
I've parsing a xml file in a a tableView.
Then u can press each row for detail info in another view.
In the rootView there is also a searBar as told where I just
reading the text from that right in to an global variable.
Who should replace the string where the url is getting the xml.
But im not sure the global variable working, i know it's working when I writing the search text myself directly in the code.
Hm.. you probably don't have any answers for this.
But it was worth a try :]
|
|
|
03-11-2009, 11:08 AM
|
#5 (permalink)
|
|
New Member
Join Date: Jan 2009
Posts: 77
|
Inside of that function I said to put a break point if the break point is being hit you need to make sure you return an UITableViewCell to represent the searched XML.
Ex.
Code:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if(!cell) cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];
//the myXML valuesForSearch is not a real method. It represents something you will
//have to do get an array of values from the XML for the passed string. I assume you
//will return an array and get the appropiate object using indexPath.row
cell.text = [[myXML valuesForSearch:passedString] objectAtIndex:indexPath.row];
return cell;
I hope that helps
|
|
|
03-11-2009, 11:47 AM
|
#6 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 35
|
I've used some methods from this tutorial:
Parsing XML Files - iPhone SDK Articles
It's a xml listed with boats and the method looks like this:
I don't use any array to return.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
Boat *newBoat = [appDelegate.boats objectAtIndex:indexPath.row];
cell.text = newBoat.model;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Set up the cell
return cell;
}
This if a function in AppDelegate.m
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSString *xmlStart = @"http://www.mysite.com/search=";
NSString *searchWord = passedString;
NSString *xmlEnd = @"&xml=1";
NSString *newString;
newString = [xmlStart stringByAppendingString:searchWord];
XML = [newString stringByAppendingString:xmlEnd];
NSURL *url = [[NSURL alloc] initWithString:XML];
NSXMLParser *boatListParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
BoatListParser *parser = [[BoatListParser alloc] initBoatListParser];
[boatListParser setDelegate:parser];
BOOL success = [boatListParser parse];
if(success)
NSLog(@"Success");
else
NSLog(@"Error");
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
Last edited by lajloos; 03-11-2009 at 11:56 AM.
|
|
|
03-11-2009, 12:52 PM
|
#7 (permalink)
|
|
New Member
Join Date: Jan 2009
Posts: 77
|
The problem is that applicationDidFinishLaunching only occurs once so the passedString value will never be searched again if changed.
Try this in the app delegate
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application{
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
//Implement your own boats getter
- (NSArray*)boats{
//I recommend surrounding all of this code before the return with an if statement
//checking to see if passedString has changed to prevent duplicate web calls
NSString *xmlStart = @"http://www.mysite.com/search=";
NSString *searchWord = passedString;
NSString *xmlEnd = @"&xml=1";
NSString *newString;
newString = [xmlStart stringByAppendingString:searchWord];
XML = [newString stringByAppendingString:xmlEnd];
NSURL *url = [[NSURL alloc] initWithString:XML];
NSXMLParser *boatListParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
BoatListParser *parser = [[BoatListParser alloc] initBoatListParser];
[boatListParser setDelegate:parser];
BOOL success = [boatListParser parse];
if(success)
NSLog(@"Success");
else
NSLog(@"Error");
return (boats parsed from xml); //This is where you return the array of BOAT objects
}
|
|
|
03-12-2009, 06:48 AM
|
#8 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 35
|
Well, now it works!
I just moved all the xml codes in applicationDidFinishLaunching to the searchButton Method.
And then I deleted the global variable because i didnt need that anymore.
Now it's working perfectly.. Thank you for your time!!!!!!
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 511 |
| 56 members and 455 guests |
| aoredsson, beausejour, bensj, BustinStones, chinhminhdo, CHV, codeMonkey, conanjb, CoolApps, Corey, CunningCat, dany88, dda, DorkyMohr, dre, ggalante, healthyutech, iPhoneDevelopment, Jeremy1026, john3478, jorgmart, JoshuaCaputo, katyaskr, KennyChong, kkrimmer, LoDani, LunarMoon, macoholic, Maximilian, mlo, MMan, Mr Jack, mriphoneman, MrMattMac, Nightmare_82, not_too_shabby, NSeven, opetopic, pablo.roqueta, pablox, pierotofy, rarindeed, Rudy, ryguy2503, salva, seriessix, sgraves, stubbsjoe, supudo, Tambourin, themathminister, virvalid, Vivek Nirkhe, warmi, wuf810, ZunePod |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,495
Threads: 35,777
Posts: 156,729
Top Poster: smasher (2,448)
|
| Welcome to our newest member, AnuSambath |
|