0

C# で作成されたバックエンドがあり、iOS から WCF 呼び出しを行っています。それはかなりうまく機能しますが、私は問題のコードで立ち往生しています:

#import "ListTableViewController.h"
#import "ListServiceSvc.h"
#import "LoginViewController.h"

@interface ListTableViewController (){
    NSMutableArray *productsFromWebServer;
    NSMutableDictionary *prodForList;
}
@property (nonatomic, retain) NSMutableArray *shoppingList;
@property (nonatomic, retain) NSMutableArray *productList;

@end

@implementation ListTableViewController

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

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    Boolean b = [standardUserDefaults boolForKey:@"HasTokenKey"];
    if (!b)
    {
        [self showLoginViewController];
    }
    [self loadListsFromRemoteServer];
    [self.tableView reloadData];
    //self.uname.text = [standardUserDefaults objectForKey:@"username"];
}

- (void) showLoginViewController {
    LoginViewController* loginController = (LoginViewController*) [ApplicationDelegate.storyBoard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [self presentViewController:loginController animated:YES completion:nil];
}

- (void)userDidLeave
{
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    [standardUserDefaults setBool:NO forKey:@"HasTokenKey"];

    // Show the Login screen. 
    [self showLoginViewController];
}

- (IBAction)exitAction
{
    [self userDidLeave];
}

- (void)viewDidLoad
{
    _shoppingList = [NSMutableArray array];
    _productList = [NSMutableArray array];
    //[self loadListsFromRemoteServer];
    [super viewDidLoad];
}

-(void) loadListsFromRemoteServer
{
    NSString *uname = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
    NemListBinding *binding  = [[ListServiceSvc NemListBinding]initWithAddress:@"http://balder/dm76_gr5/WCF.ListService.svc/custom?singleWsdl"];
    binding.logXMLInOut=YES;
    ListServiceSvc_GetShoppingListsWithUname *parms = [[ListServiceSvc_GetShoppingListsWithUname alloc]init];
    parms.uname = uname;
    [binding GetShoppingListsWithUnameAsyncUsingParameters:parms delegate:self];
}

-(void) loadItemsInList:(NSNumber*)slistId
{
    NemListBinding *binding  = [[ListServiceSvc NemListBinding]initWithAddress:@"http://balder/dm76_gr5/WCF.ListService.svc/custom?singleWsdl"];
    binding.logXMLInOut=YES;
    ListServiceSvc_GetProductsWithListId *parms = [[ListServiceSvc_GetProductsWithListId alloc]init];
    parms.listId = slistId;
    [binding GetProductsWithListIdAsyncUsingParameters:parms delegate:self];
}

- (void) operation:(NemListBindingOperation *)operation completedWithResponse:(NemListBindingResponse *)response
{
    NSArray *responseHeaders = response.headers;
    NSArray *responseBodyParts = response.bodyParts;
    [NSThread sleepForTimeInterval:1.0];
    NSMutableArray *shoppingListFromWebserver = [[NSMutableArray alloc] init];
    productsFromWebServer = [[NSMutableArray alloc]init];
    prodForList = [[NSMutableDictionary alloc]init];
    // step 1 fill in the blanks.
    for(id header in responseHeaders) {
        // here do what you want with the headers, if there's anything of value in them
    }
    for (id mine in responseBodyParts)
    {
        if ([mine isKindOfClass:[ListServiceSvc_GetShoppingListsWithUnameResponse class]])
        {
            for (id slist in [[mine GetShoppingListsWithUnameResult] ShoppingList])
            {
                [shoppingListFromWebserver addObject:slist];
                [self loadItemsInList:[slist ShoppingListId]];
//NSLog(@"new list :: RESPONSE FROM SERVER :: nList %@", [slist ShoppingListName]);
            }
        }
        if ([mine isKindOfClass:[ListServiceSvc_GetProductsWithListIdResponse class]])
        {
            for (id products in [[mine GetProductsWithListIdResult] Product])
            {
                [prodForList setObject:[products ProductName] forKey:[products ShoppingListId]];
                NSLog(@"new product :: RESPONSE FROM SERVER :: nList %@", [products ProductName]);
            }
        }
    }
    [self performSelectorOnMainThread:@selector(updateNewView:) withObject:shoppingListFromWebserver waitUntilDone:NO];
}

-(void) updateNewView:(NSMutableArray*) result
{
    _shoppingList = result;
    NSLog( @"new list - number of news :: %u", [_shoppingList count]);

    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1; // the number of different sections in your table view
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [_shoppingList count]; // the number of data in your shopping list
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ListCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    // Configure the cell...

    id shopList = [_shoppingList objectAtIndex:indexPath.row];

    cell.textLabel.text = [shopList ShoppingListName];
    NSNumber *sid = [shopList ShoppingListId];
    //[self loadItemsInList:sid];
    NSNumber *prodcount = [prodForList objectForKey:sid];
    NSString* pcTostring = [NSString stringWithFormat:@"%@", prodcount];
    cell.detailTextLabel.text = pcTostring;

    return cell;

ログは実際に、取得した最後のリストの製品をいくつか取得していることを示しています。問題はcell.detailText.text、最後のリロードまですべてのフィールドがnullであり、その後すべてのセルが消えることです。

私はそれを間違っていると確信していますが、選択したリストの製品を取得するために頭を熱くすることは-(void) loadListsFromRemoteServerできません。-(void) loadItemsInList:(NSNumber*)slistId

wsdl2obj の助けを借りて WCF 接続が行われました

4

0 に答える 0