Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:38:36+00:00 2026-05-24T07:38:36+00:00

I’m loading JSON data in a table view. The problem is that if I’m

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:38:36+00:00Added an answer on May 24, 2026 at 7:38 am

    In .h file

    #import <UIKit/UIKit.h>
    
    @interface LuckyNumbersViewController : UIViewController {
        IBOutlet UILabel *label;
        NSMutableData *responseData;
        NSArray *luckyNumbers;
        IBOutlet UITableView *tbl;
        NSMutableArray *arrForData;
    }
    @property(nonatomic,retain) NSArray *luckyNumbers;
    @property(nonatomic,retain) NSMutableArray *arrForData;
    @end
    

    In .m File

    #import "LuckyNumbersViewController.h"
    #import "JSON/JSON.h"
    
    @implementation LuckyNumbersViewController
    @synthesize luckyNumbers;
    - (void)viewDidLoad {   
        [super viewDidLoad];
    
        responseData = [[NSMutableData data] retain];       
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.1040communications.net/sheeba/stepheni/iphone/stephen.json"]];
        [[NSURLConnection alloc] initWithRequest:request delegate:self];            
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
        [responseData setLength:0];
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
        [responseData appendData:data];
    }
    
    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
        label.text = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {      
        [connection release];
    
        NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
        [responseData release]; 
        NSError *error;
        SBJSON *json = [[SBJSON new] autorelease];
        self.luckyNumbers = [json objectWithString:responseString error:&error];
        NSLog(@"numbers of the items are ::>>%i",[[self.luckyNumbers valueForKey:@"items"]count]);
        [responseString release];
        [tbl reloadData];
    }
    #pragma mark Table view methods
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    
    
    // Customize the number of rows in the table view.
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [[self.luckyNumbers valueForKey:@"items"]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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    
        cell.textLabel.text=[[[self.luckyNumbers valueForKey:@"items"]objectAtIndex:indexPath.row]valueForKey:@"title"];
        // Set up the cell...
    
        return cell;
    }
    
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // Navigation logic may go here. Create and push another view controller.
        // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
        // [self.navigationController pushViewController:anotherViewController];
        // [anotherViewController release];
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    @end
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.