Ios5 调用WCF服务后重新加载tableview

Ios5 调用WCF服务后重新加载tableview,ios5,uitableview,xcode4.3,sudzc,Ios5,Uitableview,Xcode4.3,Sudzc,我正在调用WCF服务以在UITableViewController中显示数据。文件.m中的代码为: - (void)viewDidLoad { [super viewDidLoad]; [docTable setDataSource:self]; [docTable setDelegate:self]; } -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; EDViPad

我正在调用WCF服务以在UITableViewController中显示数据。文件.m中的代码为:

- (void)viewDidLoad
{
  [super viewDidLoad];
  [docTable setDataSource:self];
  [docTable setDelegate:self];
}

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    EDViPadDocSyncService *service = [[EDViPadDocSyncService alloc]init];
    EDVCategory *cat = [EDVCategory alloc];
    cat.categoryId = [catId intValue];
    [service getDocsByCatId:self action:@selector(getDocsByCatIdHandler:) category:cat];
    [docTable reloadData];
}

- (void) getDocsByCatIdHandler: (id)value 
{
if([value isKindOfClass:[NSError class]]) 
    {
    NSLog(@"%@", value);
    return;
}
if([value isKindOfClass:[SoapFault class]]) 
    {
    NSLog(@"%@", value);
    return;
    }               
    NSMutableArray* result = (NSMutableArray*)value;
    NSMutableArray *documentList = [[NSMutableArray alloc] init];
    self.myDocList = [[NSMutableArray array] init];
    for (int i = 0; i < [result count]; i++)
    {
       EDVDocument *docObj = [[EDVDocument alloc]init];
       docObj = [result objectAtIndex:i];
       [documentList addObject:[docObj docName]];        
    }
    self.myDocList = documentList;
    [docTable reloadData];
}

- (void)viewDidUnload
{  
   [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int cnt = [self.myDocList count];
    NSLog(@"ABC=%@",cnt);
    return [self.myDocList count];
    //return 1;
 }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   DocumentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DocumentCell"];
   if (cell == nil)
   {
      cell = [[[DocumentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DocumentCell"] autorelease];
   }
   NSLog(@"cell text=%@",[self.myDocList objectAtIndex:indexPath.row]);
   cell.lblDocName.text = [self.myDocList objectAtIndex:indexPath.row];
   return cell;
}
-(void)viewDidLoad
{
[超级视图下载];
[可修改的setDataSource:self];
[docTable setDelegate:self];
}
-(无效)视图将显示:(BOOL)动画
{
[超级视图将显示:动画];
EDViPadDocSyncService*服务=[[EDViPadDocSyncService alloc]init];
EDV类别*类别=[EDV类别分配];
cat.categoryId=[catId intValue];
[服务getDocsByCatId:self action:@selector(getDocsByCatIdHandler:)类别:cat];
[可修改的重新加载数据];
}
-(void)getDocsByCatIdHandler:(id)值
{
if([value iskindof类:[n错误类]])
{
NSLog(@“%@”,值);
返回;
}
if([value iskindof类:[SoapFault类]])
{
NSLog(@“%@”,值);
返回;
}               
NSMutableArray*结果=(NSMutableArray*)值;
NSMutableArray*documentList=[[NSMutableArray alloc]init];
self.myDocList=[[NSMutableArray]init];
对于(int i=0;i<[结果计数];i++)
{
EDVDocument*docObj=[[EDVDocument alloc]init];
docObj=[结果对象索引:i];
[documentList addObject:[docObj docName]];
}
self.myDocList=文档列表;
[可修改的重新加载数据];
}
-(无效)视图卸载
{  
[超级视频下载];
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回YES;
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
int cnt=[self.myDocList计数];
NSLog(@“ABC=%@”,cnt);
返回[self.myDocList count];
//返回1;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
DocumentCell*单元格=[tableView dequeueReusableCellWithIdentifier:@“DocumentCell”];
如果(单元格==nil)
{
cell=[[DocumentCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:@“DocumentCell”]自动释放];
}
NSLog(@“cell text=%@,[self.myDocList objectAtIndex:indexath.row]);
cell.lblDocName.text=[self.myDocList objectAtIndex:indexath.row];
返回单元;
}

我正在使用故事板。我已挂接“docTable”,将数据源和委托设置为“docTable”。问题是,在调用“numberOfRowsInSection”后调用了该服务。因此,“return[self.myDocList count]”为0。我已将[docTable reloadData]视图中的以及服务处理程序中的,也就是说,“getDocsByCatIdHandler”。但它不会像预期的那样重新加载。还有什么我可以尝试的吗编辑:-这是一个主详细信息应用程序。我在“MasterViewController”UITableViewController中加载数据时使用了相同的代码,它可以工作。当用户选择此表中的单元格时,我需要通过调用WCF服务来填充第二个tableview中的数据。第二个tableview没有显示数据。

一切看起来都很好,这让我相信您没有从您期望的Web服务中获得结果

首先一件小事,那不是你的问题。若结果实际上是一个数组,并且其中有一个对象,那个么您不需要分配一个新的EDVDocument

EDVDocument *docObj = [result objectAtIndex:i];
您可以记录(id)value参数以查看我们正在处理的内容吗

NSLog(@"%@", value);
如果值不是数组,演员不会抱怨,它只会通过不工作来工作。但是,如果它是一个数组,您可能会发现将您的属性(假定我不知道它是如何声明的)分配到本地数组时遇到问题。可以使用以下函数使用临时数组的元素创建新数组

self.myDocList = [[NSArray alloc] initWithArray:documentList];
[docTable reloadData];

我希望这能有所帮助。

我在进行异步Web服务调用时也遇到了同样的问题。我使用一个私有库来调用webservice,所以我的控件会转到该库,在响应之后,Appdelegate中的一个方法被设置为handler。因此,您需要做的是在调用Webservice之前,将tableview的状态保存在共享变量中,在收到响应之后,将其设置回tableview,然后调用reload方法。如下所示:

SharedView.tblView = self.tableView; 
[webservice Call];

After Response:
 self.tableView = SharedView.tblView;
[self.tableView reloadData];

希望这有帮助。

:-嗯,“value”的NSLog是一个数组。所以,这不是问题。唯一的问题是表没有重新加载。我已经尝试了你的建议,但它们的工作原理与我的代码相同。我唯一的问题是重新加载表。对web服务的调用工作正常,并返回一个数组。我还需要查看其他内容吗?@from.nett我不确定,请先尝试删除viewWillLoad中的重新加载数据,并密切关注您的控制台。您应该看到
ABC=cnt
两次,第一次是
ABC=0
,第二次是在服务处理程序之后,使用
[结果计数]
。您看到它多少次了?“ABC”只出现一次。因此,尽管我调用了[docTable reloadData],但“numberOfRowsInSection”只被调用了一次。方法调用的顺序是:(1)viewDidLoad(2)View将出现(3)numberOfSectionsInTableView(4)应自动旋转指针FaceOrientation(5)numberOfSectionsInTableView(6)numberOfRowsInSection(7)调用web服务。即使我在web服务调用后“重新加载”表,也不会调用“numberOfRowsInSection”。不知道该告诉你什么,重新加载数据应该会导致再次调用委托方法。如果不是,那么tableView将被设置为nil,或者数据源将被重新分配。你用的是故事板还是笔尖?也许这就是设置数据源/代理的地方,而
docTable
没有作为出口连接?我正在使用一个故事板,我已经将docTable挂接为出口。我还在故事板中设置了数据源和代理出口。该.h文件如下所示:
#import@interfaceDocumentViewController:UITableViewController@property(非原子,保留)IBOut