Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-11-2009, 08:20 AM   #1 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 35
Default 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 :]
lajloos is offline   Reply With Quote
Old 03-11-2009, 08:52 AM   #2 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 35
Default

..

Last edited by lajloos; 03-11-2009 at 10:54 AM.
lajloos is offline   Reply With Quote
Old 03-11-2009, 09:06 AM   #3 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 77
Default

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.
JoeBlaze is offline   Reply With Quote
Old 03-11-2009, 09:58 AM   #4 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 35
Default

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 :]
lajloos is offline   Reply With Quote
Old 03-11-2009, 10:08 AM   #5 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 77
Default

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
JoeBlaze is offline   Reply With Quote
Old 03-11-2009, 10:47 AM   #6 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 35
Default

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 10:56 AM.
lajloos is offline   Reply With Quote
Old 03-11-2009, 11:52 AM   #7 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 77
Default

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
}
JoeBlaze is offline   Reply With Quote
Old 03-12-2009, 05:48 AM   #8 (permalink)
New Member
 
Join Date: Mar 2009
Posts: 35
Default

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!!!!!!
lajloos is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 229
16 members and 213 guests
benoitr007, codezy, dbonneville, hit1983, iphonedave, irishkiwi, Jompe71, leeks, mizyeh, myPhone, n8r0n, pkouame, prathumca, Rashomon, shuvo1879, smilespray
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,279
Threads: 39,072
Posts: 171,328
Top Poster: smasher (2,575)
Welcome to our newest member, yogen81
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:09 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0