-3

NSURLConnectiontableViewの前にプログラムが機能しないのはなぜですか?

//  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

ログ:

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"
) 

配列にはデータがありますが、tableViewにはありませんnumberOfRowsInSection

このコードの前は、(WSDLではなく)XMLを使用しています。

これは私のコードです-> http://www.vasuta.com/ios/MyLoxFile.zip

4

3 に答える 3

0

NSArrayを更新した後、[uitableview reloadData]を使用しましたか?

于 2012-09-11T08:52:53.020 に答える
0

NSURLConnectionのダウンロードが完了する前に、テーブルビューがロードされ、デリゲートメソッドが呼び出されているようです。NSURLConnectionを起動しました

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

したがって、接続は非同期です。テーブルビューがビューをロードする前に終了したのか、後に終了したのかを確認することはできません。ただし、アプリを機能させるために、テーブルビューメソッドをいつでもチェックできます。例えば:

- (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;
 }

メソッド「ConnectionDidFinishLoading」で、[tableviewreloaddata]を呼び出してテーブルビューを更新できます。

[編集]2012年12月9日

私はあなたのコードを動作させました(良い解決策ではありません)、あなたはあなたのviewControllersをどのように編成するかを再考する必要があります。

  1. IBOutletTableViewをmyloxfileController.tableViewに追加します。インターフェイスの行の後myloxfileContoller.tableView = myloxfileTable;にこの行を追加します。myloxfileContoller.view = myloxfileContoller.tableView;- (void)viewDidLoadViewController

  2. 接続が終了したら、テーブルビューデータをリロードします。インターフェイスの行の後[self.tableView reloadData];にこの行を追加します。items_subject = subject_data_Array;-(void)connectionDidFinishLoading:(NSURLConnection *)connectionMyLoxFileTVController

これが機能するのは、ダウンロードが終了したときに、IBOutletTableViewのDataをreloadするためです。

于 2012-09-11T08:57:06.120 に答える
0

と置換する

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"tableView numberOfRowsInSection"); //debug
    // Return the number of rows in the section.
    NSLog(@"[items_subject count] = %@ ", [items_subject count]);
    return [items_subject count];
}
于 2012-09-11T12:18:14.307 に答える