This is my full code
I'm using http://code.google.com/p/json-framework/ for my JSON connection
my Json is returned in this format:
[
{
"id": "7812",
"title": "title1",
"fulltext": "main body text",
"created": "2010-04-06 11:30:03"
},
{
"id": "7813",
"title": "title2",
"fulltext": "main body text2",
"created": "2010-04-06 11:30:03"
}
]
MainNewsController.h
in here declare:
NSArray *list:
@property (nonatomic, retain) NSArray *list;
MainNewsController.m
@synthesize list;
-(void) viewDidLoad
{
NSArray *array = [[NSArray alloc] initWithArray: [self downloadPublicJaikuFeed]];
self.list = array;
NSArray *stream = [list objectAtIndex:6]; // can change index and it's fine
NSString *vall = [stream valueForKey:@"title"]; // works fine
NSString *val1l = [stream valueForKey:@"id"]; // works fine
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.list count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MainNewsCellIdentifier = @"MainNewsCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: MainNewsCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: MainNewsCellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
NSDictionary *stream = (NSDictionary *) [list objectAtIndex:row];
cell.textLabel.text = [stream valueForKey:@"id"];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[stream release];
return cell;
}
#pragma mark -
#pragma mark Table Delegate Methods
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (childController == nil)
childController = [[MainNewsDetailController alloc] initWithNibName:@"DisclosureDetail" bundle:nil];
childController.title = @"News Detail Button Pressed";
NSUInteger row = [indexPath row];
NSArray *stream = (NSArray *) [self.list objectAtIndex:row];
NSString *vall = [stream valueForKey:@"title"]; // error
NSString *val1l = [stream valueForKey:@"id"]; // error
childController.message = @"111";
childController.title = @"222";
[self.navigationController pushViewController:childController animated:YES];
}