I would not like to break into two questions, I will try to ask them here: 1) Could someone explain the reason for not calling viewWillAppear: The user opens a modal window, from this modal window, the [self.navigationController pushViewController ..] is done and the opened controller viewWillAppear is called. I understand that the modal window doesn’t really do such actions as pushViewController, but still why there is no method call and how can I get rid of this problem?

Example: We called the modal controller and are now on it. There is a button:

- (IBAction)tapOnButton:(id)sender { UserViewController *userViewController = (UserViewController *)[UIViewController userProfileViewController]; userViewController = ProfileControllerModeEditing; [self.navigationController pushViewController: userViewController animated:YES]; } 

By clicking on it, we switch to another controller, in which the viewWillAppear method is not called. I simply subscribe to the observer in viewWillAppear in the userViewController controller. It turns out that when I switch to this controller and the viewWillAppear method (in which I subscribe to the observer) is not called, when I close this controller, I unsubscribe from the observer and get an error. I think the problem arises somewhere in the controller stack, when I am pushViewController from a modal controller.

2) When creating a table, I need to add only an object to the first cell (indexPath.row == 0), the path will be a UIView - some small colored square ([cell addSubView: view]). When scrolling, the cells are redrawn and the added view appears on several cells (although I added it with the condition indexPath.row == 0). I read that it is not desirable to add an object to a cell via addSubView: view, but how can you avoid this problem if you need to create an object of another class and put it on one cell? (I tried if (! Cell)). I would appreciate answers

UPDATE:

1) The problem turned out to be a little different, did not see the chain of calls.

What was: The modal window A was called, pushViewController was made from this modal window to controller B, which was a container and added class C to this container. Accordingly, in class C, the viewWillAppear method was not called in which I needed to sign on the observer.

Solution: Call the following method (BOOL) automatically ForwardAppearanceAndRotationMethodsToChildViewControllers {return NO; }

Now you can use the methods viewWillAppear, viewWillDisappear ..

2) Just use the - (void) prepareForReuse {..} method to remove an object from other cells, although I don’t think this is the optimal solution.

  • write a minimal example showing your problem with viewWillAppear. - Max Mikheyenko
  • I added a small example which, I hope, explains my problem a little clearer - ed8009
  • meant a project that you can run and debug a problem - Max Mikheyenko
  • Well, I will try to pull this problem out of a larger project and send it here, in any case, accomplish your goal if I manage to correct and understand the cause myself - ed8009
  • Check your VC chain. Most likely, in one or more of them, somewhere in methods like -viewWillApperar: -viewDidDisappear: you do not call super . It is also possible that a VC was not added to the stack by the -addChildViewController: method -addChildViewController: followed by the call -didMoveToParentViewController: - bteapot 5:27 pm

0