I'm really stumped here.
_vc = [[VLCKitViewControlleriPhone alloc]initWithNibName:#"VLCKitViewControlleriPhone" bundle:nil];
_vc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:_vc animated:YES completion:nil];
Gives me EXC_BAD_ACCESS (code = 2, address = 0x0) when the presentViewController method is called. The view controller is NOT nil. It also happens with or without a nib name. If I comment out the presentViewController line, the rest of the code continues fine, including method calls made to the view controller itself. The view controller is running, I just can't see anything because it's not actually showing the view.
I enabled NSZombies and tried it with Instruments running, but it's not showing me anything. The app just quits and instruments stops without giving me any information. Anyone know what the problem might be?
You can try this
if ([controller respondsToSelector:#selector(setModalPresentationStyle:)])
{
[controller setModalPresentationStyle:UIModalPresentationFullScreen];
} else {
[controller setModalPresentationStyle:UIModalPresentationFormSheet];
}
Related
I'm trying to present a custom UIViewController with one method and dismiss the same UIViewController from another method.
The method being used to present the controller:
-(void)presentViewController {
self.customView = [[UIViewController alloc] init];
[self.customView setModalPresentationStyle: UIModalPresentationOverFullScreen];
[self presentViewController:self.customView animated:YES completion:nil];
}
The method being used to dismiss the controller:
-(void)dismissViewController {
[self.customView dismissViewControllerAnimated:YES completion:nil];
}
When creating a button within my customView, that calls dismissViewController, nothing happens. I know the method is being called because the completion: tag is working, yet nothing happens visually. No errors are being printed to console either.
Maybe I'm doing the whole thing wrong but any help is appreciated! Just trying to learn.
As in the title, I do not manage to have that callback called in order to dismiss the game center view controller neither on my iOS 7 iPhone nor iOS 8 iPad. This is the code I use:
GKGameCenterViewController *controller=nil;
- (IBAction)achievementButtonClicked:(id)sender {
if (!controller){
controller=[[GKGameCenterViewController alloc] init];
controller.delegate=self;
}
NSLog(#"controller=%#", controller);
if (controller) [self presentViewController:controller animated:YES completion:nil];
}
-(void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
[gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
// I also tried [self dismissViewControllerAnimated:YES completion:nil] but anyway the function seems to not even enter here
}
If I take the function off, the delegate complaints it is missing, so the issue should not be connected to that. What might that be and how to fix it?
My problem is that I used:
controller.delegate=self;
omitting:
controller.gameCenterDelegate = self;
Once inserted the latter, the view controller dismisses without problems, both when I manually present the controller and when it is shown to login her. I really wonder why that beast has too delegates, if not to confuse developers...
I am getting the error:
Application tried to present modally an active controller
when I attempt to run my code below.
I am wanting to present a modal view-controller that is embedded within a UINavigationController. I have the navigationVC instantiated before this point. I only get this error when I run this code a second time. What I mean is that if I click a button and it runs this code it will work properly. I can than modally close that view. If I click the same button again to run it once more, I am getting error.
- (void)pushToUserProfile
{
if (!self.profileVC) {
self.profileVC = [self.storyboard instantiateViewControllerWithIdentifier:#"profileVC"];
[self.profileVC setCanEditProfile:NO];
[self.profileVC setTitle:#"Profile"];
[self.profileVC setCanCloseModal:YES];
}
[self.navigationVC setViewControllers:#[self.profileVC]];
[self presentViewController:self.navigationVC animated:YES completion:nil];
}
What am I doing wrong below?:
edit:
I also run the code:
- (void)writeComment
{
if (!self.writeCommentVC) {
self.writeCommentVC = [self.storyboard instantiateViewControllerWithIdentifier:#"writeCommentVC"];
}
[self.navigationVC setViewControllers:#[self.writeCommentVC]];
[self presentViewController:self.navigationVC animated:YES completion:nil];
}
and it works with no issue. Not matter how many times I present/dismiss that view controller.
Okay, so I have just started iOS development. I'll start by explaining the flow of my app :
1. A view called "appViewController" is loaded.
2. [self presentViewController: controller animated: YES completion:nil]; this loads a webview
3. After I am done with the webview, I dismiss it and load a new UINavigation this way :
[self dismissViewControllerAnimated:YES completion:^{
formViewController *fv = [ [formViewController alloc] init ];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:fv] autorelease];
navController.navigationBar.hidden = YES;
[presentingViewController presentModalViewController:navController animated:YES];
}];
5.The formViewController has a button, which has the event attached to it for that display an alert this way
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Oops!"
message:#"test"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[av show];
Everything works as intended up till here. Now when I click the "Ok"(Cancel) button, the app crashes with NSZombieEnabled saying
-[appViewController _deepestDefaultFirstResponder]: message sent to deallocated instance 0x6e6a570 lldb
What is happening here? Why is it trying to send message to appViewController again? There is no code after [av show]
NOTE : I am using ARC
If you're using arc, the autorelease in your code isn't valid.
This seems like your root view controller gets deallocated at some point and when the responder chain gets traversed the resulting dangling pointer gets accessed.
To verify this, I would implement the dealloc method on appViewController and see if it gets called.
dealloc {
NSLog(#"Problems ahead.");
}
If this does get called before you'd expect that to happen (for a root view controller probably not at all), you need to find out why this happens. You're probably missing a strong reference somewhere. Check you app delegate and verify that you have a strong reference to the window and that you are setting your controller as the root view controller (provided you're not using storyboards).
The Zombies instrument is very good for debugging such problems. It will list all retains and releases of your problematic object. Here's a short introduction to it.
A couple of things.
You are mixing presentViewController and presentModalViewController. If you are new to iOS, you should always use presentViewController. No need getting used to using a method that will soon be deprecated (see answer to this question Difference between presentModalViewController and presentViewController?
In general, you shouldn't autorelease unless you absolutely have to. Since when a controller is presented with presentViewController (and presentModalViewController), it is retained, you can readily release afterwards. I would restructure like so:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:fv];
navController.navigationBar.hidden = YES;
[presentingViewController presentModalViewController:navController animated:YES];
[navController release];
3.. Where is the section of code you included located? Like, you push a button and the view is dismissed or what?
I recently encountered a hair-pulling situation in my iOS app, where I was trying to successively dismiss one presented UIViewController from my window's rootViewController, using:
[rootViewController dismissViewControllerAnimated:YES completion:NULL]
and present another one shortly thereafter (in another method, incidentally), with:
UIViewController *vc2 = [[[MyViewController2 alloc] initWithNibName:nil bundle:nil] autorelease];
[rootViewController presentViewController:vc2 animated:YES completion:NULL];
Problem was, I could never get the second view controller to show up. Turns out, as near as I can tell, dismissViewControllerAnimated:completion: needs that asynchronous block of "completion" time to pass, before presentViewController:animated:completion: will work properly again. This fact is not directly documented in Apple's docs, from what I can tell.
The solution I came up with was to wrap the dismissal with a method that specifies the selector you would want to call afterwards, like so:
- (void)dismissViewController:(UIViewController *)presentingController
postAction:(SEL)postDismissalAction
{
[presentingController dismissViewControllerAnimated:YES
completion:^{
[self performSelectorOnMainThread:postDismissalAction
withObject:nil
waitUntilDone:NO];
}];
}
And then I would call:
[self dismissViewController:self.window.rootViewController
postAction:#selector(methodForNextModalPresentation)];
Anyway, I wanted to post, as I looked around and hadn't seen anyone with this particular problem, so I thought it might be useful for people to understand. And also, I wanted to verify that I'm not hacking a solution that has a better design pattern for resolution.
Just for the sake of clarity. are you saying that this code doesn't work?
[myRootViewController dismissViewControllerAnimated:YES completion:^{
[myRootViewController pushViewController:newController animated:YES];
}];