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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:03:21+00:00 2026-06-11T15:03:21+00:00

Why doesn’t my program work in NSURLConnection before tableView? // MyLoxFileTVContoller.m #import MyLoxFileTVContoller.h #import

  • 0

Why doesn’t my program work in NSURLConnection before tableView?

//  MyLoxFileTVContoller.m

#import "MyLoxFileTVContoller.h"
#import "xml_myloxfile.h"
#import "DetailViewController.h"

@implementation MyLoxFileTVContoller
@synthesize myloxfileArray;
@synthesize exportId_data_Array,readFG_data_Array,receiverId_data_Array,referenceId_data_Array,referenceName_data_Array,reportFullPath_data_Array,reportName_data_Array,senderId_data_Array,senderName_data_Array,sentDate_data_Array,subject_data_Array; 
@synthesize detailViewController;
@synthesize window = _window;
@synthesize navigationController;
@synthesize delegate;
@synthesize unReadCount;
@synthesize webData;

-(void)doParse{

    NSLog(@"doParse"); //debug

    [myloxfileArray removeAllObjects];

    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                             "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:con=\"http://controller.exportingreportwebservice.lox.org/\">\n"
                             "<soapenv:Header/>\n"
                             "<soapenv:Body>\n"
                             "<con:getReport>\n"
                             "<arg0>%@</arg0>\n"
                             "</con:getReport>\n"
                             "</soapenv:Body>\n"
                             //"</soapenv:Envelope>\n", nameInput.text
                             "</soapenv:Envelope>\n", @"2711"
                             ];
    //NSLog(soapMessage);

    NSURL *url = [NSURL URLWithString:@"http://iloxley.loxley.co.th:8081/ExportingReportWebservice/ExportingReportWebservice?wsdl"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if( theConnection )
    {
        NSLog(@"if theConnection"); //debug
        webData = [NSMutableData data];
    }
    else
    {

        NSLog(@"theConnection is NULL");
    }

    NSLog(@"end doParse"); //debug

}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSLog(@"connection didReceiveResponse"); //debug
    [webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"connection didReceiveData"); //debug
    [webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"connectionDidFinishLoading"); //debug
    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
    //NSLog(@"theXML = %@ ", theXML);
    //NSLog(@"webData = %@ ", webData);
    //NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:theXML];
    NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithData: webData];

    // create and init our delegate
    xml_myloxfile_Parser *parser = [[xml_myloxfile_Parser alloc] initXMLParser];

    //set delegate
    [nsXmlParser setDelegate:parser];

    //parsing...
    BOOL success = [nsXmlParser parse];

    if (success) {
        NSLog(@"if success"); //debug

        exportId_data_Array = [parser getExportId_data_Array];
        readFG_data_Array = [parser getReadFG_data_Array];
        receiverId_data_Array = [parser getReceiverId_data_Array];
        referenceId_data_Array = [parser getReferenceId_data_Array];
        referenceName_data_Array = [parser getReferenceName_data_Array];
        reportFullPath_data_Array = [parser getReportFullPath_data_Array];
        reportName_data_Array = [parser getReportName_data_Array];
        senderId_data_Array = [parser getSenderId_data_Array];
        senderName_data_Array = [parser getSenderName_data_Array];
        sentDate_data_Array = [parser getSentDate_data_Array];
        subject_data_Array = [parser getSubject_data_Array];

        items_exportId = exportId_data_Array;
        items_readFG = readFG_data_Array;
        items_receiverId = receiverId_data_Array;
        items_referenceId = referenceId_data_Array;
        items_referenceName = referenceName_data_Array;
        items_reportFullPath = reportFullPath_data_Array;
        items_reportName = reportName_data_Array;
        items_senderId = senderId_data_Array;
        items_senderName = senderName_data_Array;
        items_sentDate = sentDate_data_Array;
        items_subject = subject_data_Array;

        NSLog(@"items_subject = %@ ", items_subject);


    } else {
        NSLog(@"fail");
    }

}

-(void) loadView
{
    NSLog(@"loadView"); //debug
    if (items_subject == nil) {
        //items_subject = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",nil];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"numberOfSectionsInTableView"); //debug
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"tableView numberOfRowsInSection"); //debug
    // Return the number of rows in the section.
    NSLog(@"[items_subject count] = %d ", [items_subject count]);
    return [items_subject count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"tableView cellForRowAtIndexPath"); //debug
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.textLabel.text = [NSString stringWithFormat:@"%@" ,[items_subject objectAtIndex:indexPath.row]];

    //  Populate the cell's detail text label.
    NSString *detailText = [NSString stringWithFormat:@"date: %@  from: %@  reference: %@",
                            [[items_sentDate objectAtIndex:indexPath.row] lowercaseString],[[items_senderName objectAtIndex:indexPath.row] lowercaseString],[[items_referenceName objectAtIndex:indexPath.row] lowercaseString]];


    [[cell detailTextLabel] setText:detailText];

    //CGAffineTransform translate = CGAffineTransformMakeTranslation(10.0, 0.0); 
    //[[cell detailTextLabel] setTransform:translate];

    //unReadCount = 0;

    if([[items_readFG objectAtIndex:indexPath.row] isEqualToString:@"N"]){
        cell.textLabel.textColor = [UIColor redColor];
        unReadCount = unReadCount+1;
    }else{
        cell.textLabel.textColor = [UIColor blackColor];
        unReadCount = unReadCount;
    }

    NSLog(@"unReadCount = %d ",unReadCount);

    //Adding A Badge Number
    //[[UIApplication sharedApplication] setApplicationIconBadgeNumber:unReadCount];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"tableView didSelectRowAtIndexPath"); //debug

    //sof2
    DetailViewController *detailController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
    [detailController changeExportIdText:[exportId_data_Array objectAtIndex:indexPath.row]];
    [detailController changeReadFGText:[readFG_data_Array objectAtIndex:indexPath.row]];
    [detailController changeReceiverIdText:[receiverId_data_Array objectAtIndex:indexPath.row]];
    [detailController changeReferenceIdText:[referenceId_data_Array objectAtIndex:indexPath.row]];
    [detailController changeReferenceNameText:[referenceName_data_Array objectAtIndex:indexPath.row]];
    [detailController changeReportFullPathText:[reportFullPath_data_Array objectAtIndex:indexPath.row]];
    [detailController changeReportNameText:[reportName_data_Array objectAtIndex:indexPath.row]];
    [detailController changeSenderIdText:[senderId_data_Array objectAtIndex:indexPath.row]];
    [detailController changeSenderNameText:[senderName_data_Array objectAtIndex:indexPath.row]];
    [detailController changeSentDateText:[sentDate_data_Array objectAtIndex:indexPath.row]];
    [detailController changeSubjectText:[subject_data_Array objectAtIndex:indexPath.row]];

    //[tableView deselectRowAtIndexPath:indexPath animated:YES];

    if([delegate respondsToSelector:@selector(showItemDetails:)])
    {
        //[delegate showItemDetails:[subject_data_Array objectAtIndex:indexPath.row]];
        [delegate showItemDetails:[NSString stringWithFormat:@"%@||%@||%@||%@||%@||%@||%@||%@||%@||%@||%@"
                                   ,[exportId_data_Array objectAtIndex:indexPath.row]
                                   ,[readFG_data_Array objectAtIndex:indexPath.row]
                                   ,[receiverId_data_Array objectAtIndex:indexPath.row]
                                   ,[referenceId_data_Array objectAtIndex:indexPath.row]
                                   ,[referenceName_data_Array objectAtIndex:indexPath.row]
                                   ,[reportFullPath_data_Array objectAtIndex:indexPath.row]
                                   ,[reportName_data_Array objectAtIndex:indexPath.row]
                                   ,[senderId_data_Array objectAtIndex:indexPath.row]
                                   ,[senderName_data_Array objectAtIndex:indexPath.row]
                                   ,[sentDate_data_Array objectAtIndex:indexPath.row]
                                   ,[subject_data_Array objectAtIndex:indexPath.row]
                                   ]];//test multi var'
    }

    // Alert will pop up when using Simulator or iPod Touch for example
    /*
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[note_subject_data_Array objectAtIndex:indexPath.row] message:@"Test" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
     [alert show];
     */
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    NSLog(@"viewDidLoad"); //debug

    [self doParse];

    [super viewDidLoad];
}

- (void)viewDidUnload
{
    NSLog(@"viewDidUnload"); //debug

    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

@end

The log:

2012-09-11 15:27:15.377 MyLoxFile[2698:f803] loadView
2012-09-11 15:27:15.378 MyLoxFile[2698:f803] viewDidLoad
2012-09-11 15:27:15.379 MyLoxFile[2698:f803] doParse
2012-09-11 15:27:15.382 MyLoxFile[2698:f803] if theConnection
2012-09-11 15:27:15.382 MyLoxFile[2698:f803] end doParse
2012-09-11 15:27:15.385 MyLoxFile[2698:f803] numberOfSectionsInTableView
2012-09-11 15:27:15.386 MyLoxFile[2698:f803] tableView numberOfRowsInSection
2012-09-11 15:27:15.391 MyLoxFile[2698:f803] [items_subject count] = 0 
2012-09-11 15:27:15.454 MyLoxFile[2698:f803] connection didReceiveResponse
2012-09-11 15:27:15.455 MyLoxFile[2698:f803] connection didReceiveData
2012-09-11 15:27:15.455 MyLoxFile[2698:f803] connectionDidFinishLoading
2012-09-11 15:27:15.455 MyLoxFile[2698:f803] DONE. Received Bytes: 1948
2012-09-11 15:27:15.457 MyLoxFile[2698:f803] if success
2012-09-11 15:27:15.457 MyLoxFile[2698:f803] items_subject = (
    "Surgical Report ",
    "Genotype Report",
    "HPV Report"
) 

It has data in array but not have in tableView numberOfRowsInSection

Before this code i use XML (not WSDL) it’s work

This is My Code -> http://www.vasuta.com/ios/MyLoxFile.zip

  • 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-11T15:03:23+00:00Added an answer on June 11, 2026 at 3:03 pm

    It seems like your tableview is load et call its delegates methods before your NSURLConnection finished downloading.
    You have launch NSURLConnection by

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    

    so the connection is asynchronous. You can’t be sure whether it finishes before or after your tableview loads its view.
    But your can always do a check in your tableview methods to make your app work. For example:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        int nbCount = [items_subject count];
        if (nbCount == 0)
            return 1;
        else 
            return [items_subject count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        int nbCount = [items_subject count];
        static NSString *CellIdentifier = @"Cell";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        }
    
        // Configure the cell...
        if (nbCount ==0)
            cell.textLabel.text == @"Loading";
        else
        {
            // your configuration
            cell.textLabel.text = [NSString stringWithFormat:@"%@" ,[items_subject objectAtIndex:indexPath.row]];
        }
        return cell;
     }
    

    In your method “ConnectionDidFinishLoading”, then your can call [tableview reloaddata] to update your tableview.

    [EDIT] on 12/09/2012

    I’ve got your code work(not a nice solution), you should rethink how you organize your viewControllers.

    1. add the IBOutlet TableView to myloxfileController.tableView.
      add this line myloxfileContoller.tableView = myloxfileTable; after the line myloxfileContoller.view = myloxfileContoller.tableView; in - (void)viewDidLoad of the interface ViewController .

    2. reload tableview data when connection finished.
      add this line [self.tableView reloadData]; after the line items_subject = subject_data_Array; in -(void)connectionDidFinishLoading:(NSURLConnection *)connection of the interface MyLoxFileTVController .

    This will work because when the download finished, you reloadData of the IBOutlet TableView.

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

Sidebar

Related Questions

Why doesn't Ctrl + C work to break a Python program that uses PyQt?
Doesn't seem to work for me, maybe I just doing it wrong
This doesn't work: int number = 1; String numberstring = IntToString(number); I get The
Why doesn't this code work? b if b = true Error: undefined local variable
Why doesn't this work? Some Usercontrol (name: myUserControl) with an image control (name: myImage):
Why doesn't this test case work? <?php // cards with cyrillic inidices and suits
Why doesn't this work? struct O { O(int i, int j) : i(i) ,
Why doesn't this work in VS 2010 typename std::enable_if<!std::has_trivial_destructor<Titem>::value, BOOL>::type Clear() { ... }
autowrite doesn't seem to work when switching tab in vim. Is there a way
This doesn't work. I've got an exception from SQL databse that column does not

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.