Iphone 当源为NSURLConnection并获取新数据时重新加载tableview

Iphone 当源为NSURLConnection并获取新数据时重新加载tableview,iphone,uitableview,nsurlconnection,Iphone,Uitableview,Nsurlconnection,我使用uitableview选项卡控制器应用程序获取NSURLconnection数据并尝试显示它。我搞不懂这个问题。如果我用一个数组替换连接,我将存储所有的深入工作,但更新不行,所以我认为tableView的结尾是好的。但是: 如果我将[[self.tableview]重新加载数据];在-(void)连接IDFinishLoading中: 这将导致视图上父行的循环。当您选择一行时,它将重新填充相同的行“标题”,而不是它的子行。如果我删除[[self.tableview]reloadData];

我使用uitableview选项卡控制器应用程序获取NSURLconnection数据并尝试显示它。我搞不懂这个问题。如果我用一个数组替换连接,我将存储所有的深入工作,但更新不行,所以我认为tableView的结尾是好的。但是:

如果我将[[self.tableview]重新加载数据];在-(void)连接IDFinishLoading中:

这将导致视图上父行的循环。当您选择一行时,它将重新填充相同的行“标题”,而不是它的子行。如果我删除[[self.tableview]reloadData];tableDataSource3是空的,没有使用URL数据刷新,因此我需要它。我有显示更新的NSLogs,因此我知道它正在更新

如果我将[[self.tableview]重新加载数据];在视图中显示:

视图是空的,直到我移出表并返回(应用程序是一个带有TableView的tabcontroller)。如果我在数据库中添加一行并通过NSURL连接更新,tableView将保持原样,但如果我选择一行,则更新的新数据将显示在推送的表中

如果我将[[self.tableview]重新加载数据];在视图中,将显示:

视图是空的,直到我移出表并返回。但是,推送的子视图为空

有什么想法吗

以下是NSURL连接方法的结尾

    -(void) connectionDidFinishLoading:(NSURLConnection *)conn3 {

 ~ JSON STUFF~

  NSArray *test = [json objectForKey:@"Rows"];
  tableDataSource3 = [[NSArray alloc] initWithArray:test];


  [json release];
  [conn3 release];
  self.receivedData =nil;
  [[self tableview] reloadData];
    }
以下是选择方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

  //Get the dictionary of the selected data source.
 NSDictionary *dictionary = [self.tableDataSource3 objectAtIndex:indexPath.row];

 //Get the children of the present item.
 NSArray *Children = [dictionary objectForKey:@"Children"];

 if([Children count] == 0) {

  ItemDetailViewController *dvController = [[ItemDetailViewController alloc] initWithNibName:@"ItemDetailView" bundle:[NSBundle mainBundle]];
  [self.navigationController pushViewController:dvController animated:YES];
  [dvController release];
 }
 else {

   //Prepare to tableview.
  ThirdTab *rvController = [[ThirdTab alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];


  rvController.CurrentLevel3 += 1;


  rvController.CurrentTitle3 = [dictionary objectForKey:@"Title"];
  [self.navigationController pushViewController:rvController animated:YES];

  rvController.tableDataSource3 = Children;

  [rvController release];
 }

}

很难跟踪您所说的内容……而且您的代码需要格式化(如上所述)

试试看

  • 在-viewDidLoad中启动NSURLConnection请求
  • [[self tableView]重新加载数据]
    只能在
    connectiondFinishLoading:
    中调用,或者在NSURLConnection请求之外对数据数组进行任何更新之后调用
  • connectiondFinishLoading:
    self.tableDataSource3=[[NSArray alloc]initWithArray:test]中;在[[self tableView]重新加载数据]之前

@Jordan是的NSURL在viewDidLoad@Jordan中启动。我只在connectionDidFinishLoading结束时重新加载了一次数据。添加自我是个好主意,但我得到了同样的结果。thxI感觉整个didselectRowatIndexPath对于重载数据调用是不正确的。我发布了一个新问题。