我有一个使用 sudzc 的课程。一切正常,使用 NSLog 我可以查看我的 Web 服务的数据,但是当我想使用一个数组然后在其他地方使用该数组时,该属性为空。我想用 Web 服务的数据填充表格视图,但我不能,怎么办?
这是我的课
//
// 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
我的数据是
@property (nonatomic, 保留) NSMutableArray *myData;
谢谢