Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 09-13-2010, 09:21 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 82
shahab74 is on a distinguished road
Default Bind JSON data to uitableview

Hi could someone please point me into the right direction.I am trying to display the data from website to the uotableviw using json

my response looks like this in the console:
Code:
2010-09-14 00:11:59.620 testjson[3435:207] (
        {
        ItemAuthor = Book1;
        ItemName = "Author1";
    },
        {
        ItemAuthor = Book2;
        ItemName = author2;
    },
        {
        ItemAuthor = "Edward de Bono";
        ItemName = "How to Have a Beautiful Mind";
    }
now in the viewDidLoad I have for test only the folowing code:
Code:
- (void)viewDidLoad {
	
	NSString *scoreURL;
	scoreURL = [NSString stringWithFormat:@"http://fireball.zeon/test-json.php", @""];
	
	
	NSLog(@"%@",scoreURL);
	
	
	//start making the connection here
	NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:scoreURL]								  
											  cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
	
	// create the connection with the request
	theConnection =[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
	
	if (theConnection) 
		// start loading the data
		// Create the NSMutableData to hold the received data.
		responseData = [[NSMutableData data] retain];
	
}
In the connection finish loading I have the following code:
Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
	[connection release];
	
	
	NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
	[responseData release];
	//check if the user returned the correct data
	jsonArray = [responseString JSONValue];
	NSLog(@"%@",jsonArray);
	
	

	//NSLog(@"%i",[jsonArray count]);
	[responseString release];
	[self.tableView reloadData];
	
}
I have a rootviewcontroller with a tableview at the moment I am trying to do something like this:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *MyIdentifier = @"MyIdentifier";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
	}
	
	cell.textLabel.text = [self.jsonArray objectAtIndex:indexPath.row];

	// Set up the cell
	return cell;
}
But I do not get anything displayed in the table.
Could anyone show me the correct way to bind the response to the table.
many thanks in advance
shahab74 is offline   Reply With Quote
Old 09-13-2010, 10:03 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: Amsterdam, The Netherlands
Posts: 782
TUX2K is on a distinguished road
Default

You will also need te implement the following methode:
Code:
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
Which is in the protocl UITableViewDataSource.
If you already added this interface then you should gave be getting a warning that you need to implement this method.
TUX2K 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



» Advertisements
» Online Users: 345
13 members and 332 guests
Absentia, cgokey, fiftysixty, givensur, heshiming, iGamesDev, linkmx, michaelhansen, mraalex, PixelInteractive, raihan.zbr, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0