0

我有问题。

我有 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 main 的 reloadData 上遇到了问题![在此处输入图像描述][1]。我没有看到更新表。

帮帮我谢谢

4

1 回答 1

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];
}

谢谢

于 2013-05-07T07:04:34.860 回答