Question

File Organization

In my project the app launches in ViewController, which loads inside a table (Table class) by adding it as a subview (ViewController.h - [self.view addSubview: Table.tableView];)

Camera Class is the detailed view, so when you tap in a table row it loads Camara.xib. Until here everything works fine.

The problem comes when I try to dismiss Camera.xib and go back to ViewController.xib, when I do that Camera.xib dismisses okay but instead of going back to ViewController.xib with Table.xib inside of it, the app only loads Table.xib, so the rest of objects that were placed in the view of ViewController.xib are not displaying.

What am I doing wrong?

Thanks in advance!!

CODE:

Table.m

- (void)viewDidLoad
{

    roomsArray = [[NSMutableArray alloc] initWithObjects:nil];
    [super viewDidLoad];

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // my code...

    Camara *camara = [[Camara alloc] initWithNibName:@"Camara" bundle:nil];
    [self presentViewController:camara animated:YES completion:nil];

}

Camara.m

-(IBAction)cancel:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

ViewController.m

- (void)viewDidLoad
{

    table = [[Table alloc] initWithNibName:@"Table" bundle:nil];

    [windows.tableView reloadData];
    [self.view addSubview:windows.tableView];
    windows.tableView.transform = CGAffineTransformMakeTranslation(0, 44);

    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}

Était-ce utile?

La solution 3

the problem was that tableViewController and ViewController were in two view controllers, so I Combined them and now all works fine.

Autres conseils

Without seeing the code that you're using I cannot answer completely, but my guess is that you need to some something in viewWillAppear to reload your table or the table xib. viewWillAppear will get called every time your modal is dismissed.

The other option is to create a delegation protocol to allow your modal controller to call a method on your initial view controller.

This is a good article to start with: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

First of all I must state that your question has received downvotes, most likely because its written in poor english and initially it lacked lacks the necessary information required for a solution.

Next, I would like to stress that super calls such as [super viewDidLoad] should always come before any code logic. Move them to the top of each method.

Now as to why your having problems.

Whenever a view controller is created in memory it will execute its viewDidLoad method and then execute the viewWillAppear method just before it appears(on its parent unless your overload it), that execution only occurs once in the views lifetime. Any future attempts to display the view will result in a call to viewWillAppear.

Solution Move the following code

[windows.tableView reloadData];
[self.view addSubview:windows.tableView];
windows.tableView.transform = CGAffineTransformMakeTranslation(0, 44);

into

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [windows.tableView reloadData];
    [self.view addSubview:windows.tableView];
    windows.tableView.transform = CGAffineTransformMakeTranslation(0, 44);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top