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

  • Home
  • SEARCH
  • 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 8206009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:30:08+00:00 2026-06-07T08:30:08+00:00

this is my viewDidLoad function working well : – (void)viewDidLoad { [super viewDidLoad]; //iAds

  • 0

this is my viewDidLoad function working well :

- (void)viewDidLoad
{
    [super viewDidLoad];
    //iAds code
    adview = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adview.frame = CGRectOffset(adview.frame, 0, 0);

    adview.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    adview.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    [self.view addSubview:adview];
    adview.delegate = self;
    self.adbanerinvesiable = NO;

    //php data code
    NSError *er;
    SBJsonParser *parser = [[SBJsonParser alloc] init];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8888/newjson.php?number=1"]];
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    if (response.length != 0){
        NSString *json_string = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
        listt = [parser objectWithString:json_string error:&er];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Internet conniction" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Refresh", nil];
        [alert show];

        //for ID contet post 
        SBJsonParser *parser2 = [[SBJsonParser alloc] init];
        NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8888/newjson.php?number=2"]];
        NSData *response2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:nil error:nil];
        NSString *json_string2 = [[NSString alloc]initWithData:response2 encoding:NSUTF8StringEncoding];
        IDNum = [parser2 objectWithString:json_string2 error:&er];
    }
}

As you can see if the connection failed it will show UIAlertView and two Buttons {ok , Refresh}.

I used this Method in case the refresh button been clicked to call viewDidLoad But not Working and giving me blank white view:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 1){
        [self viewDidLoad];
    }
}

Any idea please ?

  • 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-06-07T08:30:10+00:00Added an answer on June 7, 2026 at 8:30 am

    You should put your PHP Data Code in a method in it’s own, so when you need to call that specifically you can, because you can’t (or should I say shouldn’t) call viewDidLoad manually. That should only be called automatically by UIViewController.

    Example

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        //iAds code
        adview = [[ADBannerView alloc] initWithFrame:CGRectZero];
        adview.frame = CGRectOffset(adview.frame, 0, 0);
    
        adview.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
        adview.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
        [self.view addSubview:adview];
        adview.delegate = self;
        self.adbanerinvesiable = NO;
    }
    
    -(void)viewWillAppear:(BOOL)animated    /* or: -(void)viewDidAppear: */
    {
        [super viewWillAppear:animtaed];
    
        [self refreshPHData];
    }
    
    -(void)refreshPHPData
    {
        //php data code
        NSError *er;
        SBJsonParser *parser = [[SBJsonParser alloc] init];
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8888/newjson.php?number=1"]];
        NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        if (response.length != 0){
            NSString *json_string = [[NSString alloc]initWithData:response encoding:NSUTF8StringEncoding];
            listt = [parser objectWithString:json_string error:&er];
        }
        else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Internet conniction" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Refresh", nil];
            [alert show];
    
            //for ID contet post 
            SBJsonParser *parser2 = [[SBJsonParser alloc] init];
            NSURLRequest *request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8888/newjson.php?number=2"]];
            NSData *response2 = [NSURLConnection sendSynchronousRequest:request2 returningResponse:nil error:nil];
            NSString *json_string2 = [[NSString alloc]initWithData:response2 encoding:NSUTF8StringEncoding];
            IDNum = [parser2 objectWithString:json_string2 error:&er];
        }
    }
    

    Also, when you call viewDidLoad from your UIAlertView, you are creating a second (and third and so forth) adview because you aren’t removing the previous instance. Depending on how many times the alert is shown and viewDidLoad is called, you are going to see adview stacking on top of itself. So try instead:

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
        if (buttonIndex == 1){
            [self refreshPHPData];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is how I've code to open media picker list - (void)viewDidLoad { [super
I wrote this code in my viewDidLoad function in my iOS project. lettersLeftLabel.text =
This is my program - (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line
In viewDidLoad, I have this code: ProvRec *provRec = [[ProvRec alloc]init]; provRec.status = [NSString
I can't understand why this code is throwing exception of Bad Access: - (void)viewDidLoad
Here is some simple code: // ViewControllerA.m -(void) viewDidLoad { [super viewDidLoad]; self.networkMonitor =
I have a RESTful API serving JSON. I'm calling it like this: - (void)viewDidLoad
I have the following code in my viewDidLoad method. This is a uiviewcontroller with
In my view contoller's viewDidLoad function, I have this guy: UIScrollView *scroller = [[UIScrollView
Why isn't this code working? The app loads fine, however whenever I press the

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.