IOS - open my initial view controller

I use unleash segue to relax to the initial view controller in my storyboard. Rollback works fine, I implemented this method in my first view controller:

- (IBAction) unwindToInitialViewController:(UIStoryboardSegue *) unwindSegue { } 

However, if I try to execute segue on another view controller after I do this, I get the following error:

Warning: an attempt to present whose gaze is not in the Hierarchy window!

This only seems to happen if I disconnect from the view controller, which is checked as the "Initial View Controller" in the storyboard. This is mistake? Should I be able to relax to this initial controller? Other ideas?

EDIT:

This is how I perform the second session:

 [self performSegueWithIdentifier:@"mySegue" sender:nil]; 

I should note that this is a login / logout problem. When I log in for the first time, segue will work from my controller login controller. When I log out, I unwind the source controller. Then I log in again and the session from my controller login controller does not work.

EDIT 2:

From more research, I found it because I use a delegate for my entry. The login isync, I make a call with AFNetworking, and when this is done, I call my login delegate (in this case, VC to log in). At this point, the login login can go to the view.

Login Code:

 - (void) login: (NSDictionary *) parameters { [http.manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *response) { [self.loginDelegate loginSuccess:response]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [self.loginDelegate loginFailure:error]; }]; } 

My VC login, which is the delegate:

 - (void) loginSuccess:(NSDictionary *) response { // setup user info based on response ... // Segue [self performSegueWithIdentifier:@"loginSuccessSegue" sender:nil]; } 

I checked that I am in the main stream, when I cross and still have no luck. I know that AFNetworking always causes success / failure blocks in the main thread.

The hard part. If I changed this code above to use a block rather than a delegate, then the / segue storyboard wasn’t messed up, and I can log in and log out without problems.

Why is segue working for the first time with a delegate template, but when I log out (unwind), I may not use this session again?

EDIT 3:

Further research shows that when unwinding, my VC viewDidAppear login is called twice. Upon initial shutdown, the view still remains on the stack, indicating that it is displayed quickly, and viewDidAppear is called. However, it quickly animates, and viewWillAppear is called a second time with another VC. I think this may be causing the problem. Why, when I deploy this VC, is it animated just to be animated again?

+5
source share
1 answer

Please check if your loginDelegate nil during your second login attempt. If it is nil , the "delegate calls" will simply disappear. Also check if loginDelegate to the instance you are expecting. If it points to the "old" instance, you can try to present the wrong idea.

The set of methods viewDidLoad , viewDidAppear , viewWillAppear , etc. can be called in unexpected order, especially when returning to navigation or presenting an ad and returning from it. If you have different initialization / configuration tasks distributed between these methods, you can get a partially initialized view controller.

(Thinking about the problem, I lost your statement about the error found, so maybe the delegate is not zero.)

EDIT:

I launched one of my tiny unwinding testing projects and there the viewDidAppear calls:

 viewDidAppear: <ViewController: 0x7a687700> viewDidAppear: <VC2: 0x7a70e970> viewDidAppear: <VC3: 0x7a694d50> unwind target viewDidAppear: <VC2: 0x7a70e970> viewDidAppear: <ViewController: 0x7a687700> viewDidAppear: <VC2: 0x7a71b790> viewDidAppear: <VC3: 0x7a694d20> unwind target viewDidAppear: <VC2: 0x7a71b790> viewDidAppear: <ViewController: 0x7a687700> 

VC3 in VC3 briefly shows VC2 and ultimately ends in the target ViewController . Now the second "login" leads to different instances of view managers.

Do you maintain links to "old" view controllers?

Another reason may be that the logout detection fires twice (once, when you go along the unwinding and one more time, when the intermediate or initial view controller detects the need to log in?).

+1
source

Source: https://habr.com/ru/post/1231965/


All Articles