2012-04-13 5 views
-1

私はsudzcを使用するクラスを持っています。 NSLogを使ってすべて正常に動作します。私は自分のWebサービスのデータを見ることができますが、配列を使用してその配列を別の場所で使用したい場合、そのプロパティはnullです。私は、Webサービスのデータを使ってテーブルビューを作成したいと思いますが、どうしたらいいですか?sudzcでテーブルビューを塗りつぶすにはどうすればいいですか? (私の財産は仕事をしません)

これは私のデータは

@property(アトミック、保持)NSMutableArrayの* MYDATAである私のクラス

 // 
// RootViewController.m 
// StratargetMovil 
// 
// Created by Giovanni Cortés on 30/03/12. 
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. 
// 

#import "RootViewController.h" 
#import "Page2.h" 

@interface RootViewController() 
@end 

@implementation RootViewController 
@synthesize myData = _myData; 
@synthesize empresaID = _empresaID; 
@synthesize datos = _datos; 
@synthesize idUnidadNegocio = _idUnidadNegocio; 
@synthesize idArray = _idArray; 

-(NSString *)empresaID 
{ 
    _empresaID = @"fce"; 
    return _empresaID; 
} 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
     // Do any additional setup after loading the view from its nib. 

    } 
    return self; 
} 

- (void)viewDidLoad 
{  
    // I want to fill the table view but dont work 
    EWSEmpresaWebServiceSvc *service = [[EWSEmpresaWebServiceSvc alloc] init]; 
    [service ConsultarUnidadesOrganizacionalesPorEmpresa:self EmpresaId:self.empresaID]; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
    self.datos = nil; 
    self.myData = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 



// Lo de la tabla 
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.myData count]; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease]; 

    } 

    NSUInteger row = [indexPath row]; 
    cell.textLabel.text = [self.myData objectAtIndex:row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 

} 


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Muestra la vista 2 cuando se selecciona una fila 
    [[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES]; 

    self.idUnidadNegocio = [self.idArray objectAtIndex:indexPath.row]; 

    Page2 *nextNavigator = [[Page2 alloc] init]; 

    [[self navigationController] pushViewController:nextNavigator animated:YES]; 
    [nextNavigator release]; 


} 

// ------------------------------------------------- 
// Consultar unidades organizaciones por empresa 
- (void) ConsultarUnidadesOrganizacionalesPorEmpresaHandler: (id) value { 

    // Handle errors 
    if([value isKindOfClass:[NSError class]]) { 
     NSLog(@"%@", value); 
     return; 
    } 

    // Handle faults 
    if([value isKindOfClass:[SoapFault class]]) { 
     NSLog(@"%@", value); 
     return; 
    }    


    // Do something with the NSMutableArray* result 
    NSMutableArray *result = (NSMutableArray*)value; 
    NSMutableArray *unidadOrganizacional = [[NSMutableArray alloc] init]; 
    self.myData = [[[NSMutableArray array] init] autorelease]; 

    for (int i = 0; i < [result count]; i++) 
    { 
     EWSUnidadNegocio *empresa = [[EWSUnidadNegocio alloc] init]; 
     empresa = [result objectAtIndex:i]; 
     [unidadOrganizacional addObject:[empresa Descripcion]]; 

    } 

    self.myData = unidadOrganizacional; 

} 
-(void)onload:(id)value 
{ 
    // Handle errors 
    if([value isKindOfClass:[NSError class]]) { 
     NSLog(@"%@", value); 
     return; 
    } 

    // Handle faults 
    if([value isKindOfClass:[SoapFault class]]) { 
     NSLog(@"%@", value); 
     return; 
    }    


    // Do something with the NSMutableArray* result 
    NSMutableArray *result = (NSMutableArray*)value; 
    NSMutableArray *unidadOrganizacional = [[NSMutableArray alloc] init]; 
    self.myData = [[[NSMutableArray array] init] autorelease]; 

    for (int i = 0; i < [result count]; i++) 
    { 
     EWSUnidadNegocio *empresa = [[EWSUnidadNegocio alloc] init]; 
     empresa = [result objectAtIndex:i]; 
     NSLog(@"%ld -- %@", [empresa Id], [empresa Descripcion]); // With this I can watch the data in the console 
     [unidadOrganizacional addObject:[empresa Descripcion]]; 

    } 

    self.myData = unidadOrganizacional; // self.myData in another place is null 
} 


} 
@end 

です。私はmyDataは自動解放考える

おかげ

答えて

0

まず、これはあなたのために何もしていない:

self.myData = [[[NSMutableArray array] init] autorelease]; 

... 

self.myData = unidadOrganizacional; 

あなたはすぐにそれを再割り当て、その後MYDATAを割り当てています。

は、最初の初期化をスキップし、ちょうどこの操作を行います。私はあなたには、いくつかの点でunidadOrganizacional配列へのポインタを失っているし、あなたがMYDATAにnullを取得している理由がある疑いがある

self.myData = [unidadOrganizacional mutableCopy]; 

を。その後、

- (void)viewDidLoad 
{  

    self.myData = [[NSMutableArray alloc] init]; 

    // I want to fill the table view but dont work 
    EWSEmpresaWebServiceSvc *service = [[EWSEmpresaWebServiceSvc alloc] init]; 
    [service ConsultarUnidadesOrganizacionalesPorEmpresa:self EmpresaId:self.empresaID]; 
} 

と::

- (void) ConsultarUnidadesOrganizacionalesPorEmpresaHandler: (id) value { 

    // Handle errors 
    if([value isKindOfClass:[NSError class]]) { 
     NSLog(@"%@", value); 
     return; 
    } 

    // Handle faults 
    if([value isKindOfClass:[SoapFault class]]) { 
     NSLog(@"%@", value); 
     return; 
    }    


    // Do something with the NSMutableArray* result 
    NSMutableArray *result = (NSMutableArray*)value; 

    for (int i = 0; i < [result count]; i++) 
    { 
     EWSUnidadNegocio *empresa = [[EWSUnidadNegocio alloc] init]; 
     empresa = [result objectAtIndex:i]; 
     [self.myData addObject:[empresa Descripcion]]; 
    } 
} 

-(void)onload:(id)value 
{ 
    // Handle errors 
    if([value isKindOfClass:[NSError class]]) { 
     NSLog(@"%@", value); 
     return; 
    } 

    // Handle faults 
    if([value isKindOfClass:[SoapFault class]]) { 
     NSLog(@"%@", value); 
     return; 
    }    


    // Do something with the NSMutableArray* result 
    NSMutableArray *result = (NSMutableArray*)value; 

    for (int i = 0; i < [result count]; i++) 
    { 
     EWSUnidadNegocio *empresa = [[EWSUnidadNegocio alloc] init]; 
     empresa = [result objectAtIndex:i]; 
     NSLog(@"%ld -- %@", [empresa Id], [empresa Descripcion]); // With this I can watch the data in the console 
     [self.myData addObject:[empresa Descripcion]]; 

    } 
} 

あなたはMYDATAをクリアすることもできますが、私はちょうどこれは、のviewDidLoadコールでMYDATAを初期化し、その後、直接MYDATAにオブジェクトを追加するだろうけれども個人的に

ConsultarUnidadesOrganizacionalesPorEmpresaコールの前に、私は本当にそれとonloadの間に何が違うのかは分かりません。彼らはお互いの重複のように見えます。

幸運を祈る!

+0

私は何か気づいたが、最初にテーブルビューがポップオーバーに表示されている(私はポップオーバーでテーブルビューを表示する)、そしてターミナルでデータを表示する。後でデータがロードされたためにデータを表示する – Gidrek

+0

はい、新しいデータを取得するときにtableViewをリロードする必要があります。myDataが満たされた後で[[tableView reloadData]; 'myDataデータが読み込まれ、読み込み画面が終了します。 –

+0

ありがとう、私はそれを試してみます – Gidrek

0

myDataアレイを割り当てて初期化できますが、自動/解放はできません。

myData(およびその他)の特性を解除するためのdeallocメソッドを追加することを忘れないでください( ConsultarUnidadesOrganizacionalesPorEmpresaHandler方法でmyData割り当てで自動解放を削除します)。

関連する問題