I’m loading JSON data in a table view. The problem is that if I’m scrolling the table view, my app crashes. Below is the code:
- (void)viewDidLoad {
[super viewDidLoad];
jsonurl=[NSURL URLWithString:@"http://www.1040communications.net/sheeba/stepheni/iphone/stephen.json"];
jsonData=[[NSString alloc]initWithContentsOfURL:jsonurl];
jsonArray = [jsonData JSONValue];
items = [jsonArray objectForKey:@"items"];
story = [NSMutableArray array];
description1 = [NSMutableArray array];
media1 = [NSMutableArray array];
for (NSDictionary *item in items )
{
[story addObject:[item objectForKey:@"title"]];
[media1 addObject:[item objectForKey:@"media"]];
}
NSLog(@"booom:%@",story);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [story count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[story objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[media1 objectAtIndex:indexPath.row];
return cell;
}
In .h file
In .m File
In short in Your Program their is no Retain for array thus you need to create property or it may write simple retain as above answer.