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 6126539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:23:13+00:00 2026-05-23T16:23:13+00:00

My iphone app crashes when I add a method to the viewDidLoad in my

  • 0

My iphone app crashes when I add a method to the viewDidLoad in my main viewcontroller:

#import "dbQuestionGetterViewController.h"
#import "dbConnector.h";

@implementation dbQuestionGetterViewController
@synthesize questions;

-(void)viewDidLoad{
    //code to initialise view
    NSDictionary* arr = [dbConnector getQuestions:2 from:@"http://dev.speechlink.co.uk/David/get_questions.php"];
    questions = arr;
    [arr release];  
    [super viewDidLoad];
}

I’m calling a static method from the dbConnector class, but it crashes before even loading..

The method in dbConnector:

//method to 
+(NSDictionary*)getQuestions:(NSInteger)sectionId from: (NSString*) url{
    //connect to database given by url
    //NSError        *error = nil;
    //NSURLResponse  *response = nil;
    NSMutableString* myRequestString = [[NSMutableString string]initWithFormat:@"section=%@", sectionId];
    NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: url]]; 
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    [request setHTTPMethod: @"POST"];
    //post section 
    [request setHTTPBody: myRequestData];

    //store them in the dictionary
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
    NSString *json = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSDictionary *questions = [json objectFromJSONString];
    [json release];

    [request release];
    return [questions autorelease];
}

what am i doing wrong?

  • 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-23T16:23:14+00:00Added an answer on May 23, 2026 at 4:23 pm

    First of all, you’re not doing anything with this code:

    NSMutableString* myRequestString = [[NSMutableString string]initWithFormat:@"section=%@", sectionId];
    NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: url]]; 
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
    [request setHTTPMethod: @"POST"];
    //post section 
    [request setHTTPBody: myRequestData];
    

    Remove it.

    Secondly, questions is already autoreleased.

    NSDictionary *questions = [json objectFromJSONString]; // < autoreleased
    

    So simply doing return questions; should work.

    This also means that you should not under any case release this returned value. Thus, get rid of this:

    [arr release];  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my iphone app crashes unexpectedly and looking at the crash log I can't tell
I am programming my first iPhone app (which crashes with an EXC BAD ACCESS
My iphone app crashes with the following error message: 2010-07-26 16:27:30.402 Nav[814:207] * -[UITextField
When I bring up console after my iPhone app crashes, it often says unrecognized
I'm trying to add In-App Purchase to my iPhone app. But when i run
I am trying to add music player to my iphone app using the MediaPlayer
I am building an iphone app.However my app crashes at a point when i
I have an iPhone app which uses iAd...The app crashes sometime with the following
My iphone app occasionally crashes on the simulator and device with this message in
The iPhone app that I am working on requires GET calls to a 3rd

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.