Question

Calling Code here within GameListViewController:

[self presentViewController:[[StartNewGameViewController alloc] 
initWithNibName:@"StartNewGameViewController" bundle:nil] animated:YES completion:nil];

Callback Code here within StartNewGameViewController:

[(id)self.parentViewController showSetup:m_tableID];
[self dismissViewControllerAnimated:YES completion:^{
    [GLVC showSetup:m_tableID];
}];

Also have tried:

[(id)self.GLVC showSetup:m_tableID];

Tried three different methods above here. The first method has no error, bottom method says show Setup has no known class method, third method also no error. First and third have no errors, but are not working.

.h of StartNewGameController

#import "GamelistViewController.h"
@property (nonatomic, assign) GamelistViewController *GLVC;

And I synthesize GLVC on the top of the .m

"showSetup" is a method that works just fine while called from GameListViewController and is declared in GameListViewController.h like so:

-(void)showSetup:(int)tableID;

I've seen some other stack overflow questions related to this one, but none of them have resolved my issue.

Was it helpful?

Solution

[(id)self.parentViewController showSetup:m_tableID];

works because the reference to parentViewController is automatically configured for you.

[GLVC showSetup:m_tableID];

should be _GLVC or, preferably self.GLVC and doesn't work because you never set the reference before you present the view controller. (previously it didn't work because you were using a class name, expecting it to be an instance variable name, due to bad naming, but it wasn't).

[(id)self.GLVC showSetup:m_tableID];

Is really the same as the above (in your new edited code).

The solution is to set GLVC on the created view controller before you call presentViewController:animated:completion:

StartNewGameViewController *svc = [[StartNewGameViewController alloc] initWithNibName:@"StartNewGameViewController" bundle:nil];
svc.GLVC = self;

[self presentViewController:sec animated:YES completion:nil];

OTHER TIPS

This code will do the stuff i guess. presentingViewController will automatically set it for you while presenting the controller.

[self dismissViewControllerAnimated:YES completion:^{
    [(id)self.presentingViewController showSetup:m_tableID];
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top