2013-04-19 3 views
0

У меня проблема.закрыть uitableview и перезагрузить другой uitableview

У меня есть 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];  
} 

Когда я выбираю город проходит правильно в «idCity» в TheatreController.m

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

я правильно ответ сервера и все параметры являются правильно, но проблема у меня с reloadData таблицы main! [введите описание изображения здесь] [1]. Я не вижу таблицу обновлений.

HELP ME благодаря

ответ

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

Благодарности