关闭uitableview并重新加载另一个uitableview

时间:2013-04-19 12:36:17

标签: tableview reload segue

我有问题。

我有CityViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
  TheatreController *tmpTheatreController = [storyboard instantiateViewControllerWithIdentifier:@"TheatreController"];
  NSString *cityView = [[self.arrayCity objectAtIndex:indexPath.row] valueForKey:@"idCity"];
  tmpTheatreController.cityView = cityView;

  //[self.navigationController pushViewController:tmpTheatreController animated:YES];
  [tmpTheatreController.tableView reloadData];
  [self.delegate citiesViewControllerCancel:self];    
}

当我选择城市正确传递TheatreController.m中的“idCity”

...
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if([segue.identifier isEqualToString:@"SelectCity"])
   {
      UINavigationController *nc = segue.destinationViewController;
      CityViewController *mvc = [[nc viewControllers] objectAtIndex:0];
      mvc.delegate = self;
   }
}
...
- (void)viewDidLoad
{
  [super viewDidLoad];


  NSString *webUrl = @"http://localhost:3000/theatres?city=";
  webUrl = [webUrl stringByAppendingFormat:@"%@", cityView];
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:webUrl]];
    [self performSelectorOnMainThread:@selector(fetchedData:)
                           withObject:data waitUntilDone:YES]; });
    }
- (void)fetchedData:(NSData *)responseData {
   NSArray* json = [NSJSONSerialization
                 JSONObjectWithData:responseData
                 options:kNilOptions error:nil];
   NSMutableArray *theatreTMP = [[NSMutableArray alloc] initWithCapacity:[json count]];

   int i = 0;
   for (id object in [json valueForKeyPath:@"response.name"]) {
     Theatres *t = [[Theatres alloc] init];
     NSLog(@"JSON: %@", [[json valueForKeyPath:@"response.name"] objectAtIndex:i]);
     t.theatre = [[json valueForKeyPath:@"response.name"] objectAtIndex:i];
     t.idTheatre = [[json valueForKeyPath:@"response.id"] objectAtIndex:i];

     [theatreTMP addObject:t];
     i++;
  }
 self.arrayTheatre = [theatreTMP copy];
 [self.tableView reloadData];
}

我有正确的服务器的响应和所有参数都是正确的,但我有问题与tableView主的reloadData![在此处输入图像描述] [1]。我没看到更新表。

帮助我谢谢

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题 在CityViewController.m

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cityView = [[self.arrayCity objectAtIndex:indexPath.row] valueForKey:@"idCity"];
    [self.delegate performSelector:@selector(reloadTable:) withObject:cityView];
    [self.delegate citiesViewControllerCancel:self];
}

和TheatreTableView.m

    - (void) callServer:(NSString *)idCity {
    NSString *webUrl = @"http://localhost:3000/theatres?city=";
    webUrl = [webUrl stringByAppendingFormat:@"%@", idCity];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:webUrl]];
            [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];});
}
....
- (void) reloadTable:(id)idCity
{
    [self callServer:idCity];
}

由于