dismissModalViewControllerAnimated function not dismissing the view - ios

I am trying to use dismissModalViewController:Animated: to dismiss my view, but it is not dismissing it, no matter what I try. You can see my attempts to release the view in the hideSplash method at the bottom. Please, if anyone can help it would be greatly appreciated. My code posted below:
#import "SplashViewController.h"
#implementation SplashViewController
- (void) didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void) viewDidUnload {
}
- (void) dealloc {
[super dealloc];
}
-(void) showSplash {
modalViewController = [[UIViewController alloc] init];
modalViewController.view = modelView;
[self presentModalViewController:modalViewController animated:NO];
[activityIndicator startAnimating ];
//[self bigcalculation];
//[self performSelector:#selector(hideSplash) withObject:nil afterDelay:2.0];
}
- (void) viewDidAppear:(BOOL)animated {
NSLog(#"View Did Appear");
[self bigcalculation];
}
- (void) bigcalculation {
NSLog(#"Big Calc Start");
for (int i = 0; i <= 648230; i++) {
for (int j = 0; j <= 1200; j++) {
}
}
NSLog(#"Big Calc End");
[self performSelector:#selector(hideSplash) withObject:nil];
}
- (void) hideSplash {
NSLog(#"Hide");
//[self dismissModalViewControllerAnimated:NO];
//[[self parentViewController] dismissModalViewControllerAnimated:YES];
[[self modalViewController] dismissModalViewControllerAnimated:YES];
NSLog(#"End Hide");
}
#end

The modal view controller is not responsible for dismissal. That burden is placed on the view controller that called the modalViewController.
Try replacing:
[[self modalviewController] dismissModalViewControllerAnimated:YES];
with
[self dismissModalViewControllerAnimated:YES];

Try to use this:
[self.parentViewController dismissModalViewControllerAnimated:NO];

I found the solution in case anyone else has this issue the line
[self performSelector:#selector(hideSplash) withObject:nil];
Should be
[self performSelector:#selector(hideSplash) withObject:nil afterDelay:0.0];

Related

UIViewController parent not rotating after modal view is dismissed

I have a UIViewController on an iPad that I am displaying modally.
However after dismissing it, the view controller that displayed it does not change in orientation and acts as if the underlying view controller did not change, unless the device is rotated back and forth.
I'm using these methods in the modal view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
[self updateUI];
return YES;
}
- (BOOL)shouldAutorotate {
[self updateUI];
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
-(void) updateUI{
}
The underlying UINavigationController code (the one that doesn't change itself properly once the modal view controller is dismissed):
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
[self adjustUIForOrientation:interfaceOrientation];
return YES;
}
- (BOOL)shouldAutorotate {
[self adjustUIForOrientation:[self preferredInterfaceOrientationForPresentation]];
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
- (void) adjustUIForOrientation: (UIInterfaceOrientation)interfaceOrientation {
if(UIDeviceOrientationIsPortrait(interfaceOrientation)) {
[_landscapeTemplate hide];
[_portraitTemplate show];
_activeTemplate = _portraitTemplate;
} else {
[_portraitTemplate hide];
[_landscapeTemplate show];
_activeTemplate = _landscapeTemplate;
}
}
-(IBAction) signInButtonTouched: (id) sender{
if (![Session shared].loggedInUser){
UserProfileLoginViewController *userProfileLoginVC = [[[UserProfileLoginViewController alloc] initWithNibName:#"UserProfileLoginViewController" bundle:nil] autorelease];
userProfileLoginVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
//self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:userProfileLoginVC animated:YES completion:nil];
// [self pushViewController:userProfileLoginVC animated:YES];
[userProfileLoginVC.emailTextField becomeFirstResponder];
}
else [[Session shared] explicitEnd];
}
Is there a way to make this work? Basically it appears that the view controller that presented the modal view controller is not getting the rotation calls forwarded to itself.

Hidden searchbar slides down when view shown second time

I use the following code to hide searchbar:
- (void)updateContentOffset
{
self.tableView.contentOffset = CGPointMake(0, 44);
}
- (void)viewWillAppear:(BOOL)animated
{
NSLog(#"%s",__PRETTY_FUNCTION__);
[super viewWillAppear:animated];
[self searchBarShouldEndEditing:self.searchDisplayController.searchBar];
[self performSelector:#selector(updateContentOffset) withObject:nil afterDelay:0.0];
self.fetchedResultsController.delegate = self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.fetchedResultsController performFetch:nil];
[self.tableView reloadData];
[self.tableView scrollRectToVisible:CGRectMake(0, 44, 1, 1) animated:YES];
}
The code works perfectly when view is shown for the first time.
Next time it's shown(returning from another controller) it slides a bit down than it should be and I have no idea why it happens.
OK, in my case I played with a delay and found that making it 0.1 makes it work as planned.
[self performSelector:#selector(updateContentOffset) withObject:nil afterDelay:0.1];

Achievements screen's "Done" button not working on some devices

I'm using GKAchievementViewController to display achievements. It works fine on most devices, but on some (iPod Touch 3rd Gen and iPad 1 running iOS 5.1.1) taping the Done button does nothing.
I have no idea how to debug this...
Here is the code I'm using to display the achievements:
viewController = [[GKAchievementViewController alloc] init];
if (viewController)
{
viewController.achievementDelegate = self;
[self presentModalViewController:viewController animated:YES];
}
and then:
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)aViewController
{
[self dismissModalViewControllerAnimated:YES];
}
Should work when implementing achievementViewControllerDidFinish:
- (void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
[viewController.delegate dismissModalViewControllerAnimated:YES];
}
Answering my own question in case anyone has the same problem.
This seems to have solved the issue:
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)aViewController
{
if ([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
{
[self dismissViewControllerAnimated:YES completion:^{
aViewController.achievementDelegate = nil;
[aViewController release];
}];
}
else
{
[self dismissModalViewControllerAnimated:YES];
aViewController.achievementDelegate = nil;
[aViewController release];
}
}

iOS - How do I perform two transitions sequentially?

I have taken some code from other SO questions, but I must be doing something wonky. The app jumps from the first view to the third. What I'm trying to achieve is:
ViewController 1 Image 1 - loads with an image. Quickly cross-disolves into ViewController 1 image 2.
ViewController 1 Image 2 - flips to ViewController 2.
The cross-disolve happens but takes me to VC2. I've battered at this for most of the day. It's time to ask for help while I go sit in a bathtub.
Here's what I've been doing:
- (void)viewDidLoad
{
NSLog(#"%s", __FUNCTION__);
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
NSLog(#"%s", __FUNCTION__);
sleep (2);
[self transition1]; //showing image 1
}
- (void) transition1 {
NSLog(#"%s", __FUNCTION__);
/*
[UIView transitionFromView:firstView
toView:secondView
duration:3.0
options:UIViewAnimationOptionTransitionCrossDissolve
completion:^(BOOL finished) {
[firstView removeFromSuperview];
}];
*/
//this transition doesn't happen
UIImage * secondImage = [UIImage imageNamed:#"image2.png"];
[UIView transitionWithView:self.firstView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = secondImage;
} completion:NULL];
sleep (2);
[self transition2];
}
- (void) transition2 {
NSLog(#"%s", __FUNCTION__);
self.patterns = [[PatternViewController alloc] initWithNibName:#"PatternView_iPad" bundle:nil];
self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:patterns animated:YES completion:nil];
}
Thanks for any help.
UPDATE
I've updated my code per Moxy's suggestions as follows:
- (void)viewDidAppear:(BOOL)animated {
NSLog(#"%s", __FUNCTION__);
[self performSelector:#selector(transition1)
withObject:nil
afterDelay:2.0f];
}
-(void)transition1
{
NSLog(#"%s", __FUNCTION__);
UIImage * secondImage = [UIImage imageNamed:#"image2.png"];
[UIView transitionWithView:self.firstView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = secondImage;
}
completion:^(BOOL finished){
[self performSelector:#selector(transition2)
withObject:nil
afterDelay:2.0f];
}];
}
-(void)transition2
{
NSLog(#"%s", __FUNCTION__);
self.patterns = [[PatternViewController alloc] initWithNibName:#"PatternView_iPad"
bundle:nil];
self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:patterns
animated:YES
completion:nil];
}
All you need to do is to start your second animation in the first animation's completion block.
Sleep() is something you probably shouldn't be using.
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(#"%s", __FUNCTION__);
[self performSelector:#selector(transition1)
withObject:nil
afterDelay:2.0f]
}
-(void)transition1
{
NSLog(#"%s", __FUNCTION__);
UIImage * secondImage = [UIImage imageNamed:#"image2.png"];
[UIView transitionWithView:self.firstView
duration:5.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.imageView.image = secondImage;
}
completion:^(BOOL finished){
[self performSelector:#selector(transition2)
withObject:nil
afterDelay:2.0f]
}];
}
-(void)transition2
{
NSLog(#"%s", __FUNCTION__);
self.patterns = [[PatternViewController alloc] initWithNibName:#"PatternView_iPad"
bundle:nil];
self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:patterns
animated:YES
completion:nil];
}

Very odd iOS orientation issue with Three20

This is amongst the oddest issues with iOS development I have ever seen. I'm relatively new to iOS development, so I apologize if I'm missing something obvious or my terminology isn't completely correct. If you need clarification, please let me know in the comments and I'll edit my question accordingly.
The Problem
I'm using Three20, so that might have something to do with it. But I have a "Home view" which is basically a series of images that link out to other views (shown in the image below). If I start our in portrait view, all is well.
The next view is a table view, shown below:
YAY! I can rotate and all is right with the world. BUT if I go back to that home view, rotate to landscape, and THEN go to this tabled view, the world breaks.
You'll see that there's a random space added to the right side of my table now. I don't know where and how it came from. Here's my Controller.m file:
#import "FriendTabsController.h"
#import "MyAppApp.h"
#import "JohnDoeManager.h"
#implementation FriendTabsController
#synthesize innerView, segmentedControl, innerController, friendsController, friendRequestsController;
- (void)addBottomGutter:(UIViewController*)controller {
if ([controller isKindOfClass:[TTTableViewController class]]) {
TTTableViewController* tableViewController = (TTTableViewController*)controller;
tableViewController.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,50+44,0);
tableViewController.tableView.contentInset = UIEdgeInsetsMake(0,0,50+44,0);
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Friends";
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
friendsController = [[FriendsController alloc] init];
friendRequestsController = [[FriendsController alloc] init];
((FriendsController*)friendRequestsController).friendRequests = YES;
[self addBottomGutter:friendsController];
[self addBottomGutter:friendRequestsController];
innerController = friendsController;
[innerView addSubview:innerController.view];
[innerController viewDidLoad];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
[self loadBannerAd:(orientation)];
}
-(void) loadBannerAd:(UIInterfaceOrientation)orientation{
MainLayer *mi = [MainLayer getInstance];
if (mi.useJohnDoeAds) {
[[JohnDoeManager sharedInstance] setCurrentViewController:self];
[mi.JohnDoeBanner.view removeFromSuperview];
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// This is a portait ad
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 410-44, 320, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake(0, 1024-44-90-20, 768, 90)];
}
} else {
// Landscape
if ([[MyAppUtils getCurrentDevice] isEqualToString:#"iphone"]) {
[mi.JohnDoeBanner setFrame:CGRectMake(0, 320-44-58, 410, 50)];
}else{
[mi.JohnDoeBanner setFrame:CGRectMake((1024-768)/2, 768-44-90-20, 768, 90)];
}
}
[self.view addSubview:mi.JohnDoeBanner.view];
[mi.JohnDoeBanner rollOver];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self loadBannerAd:(toInterfaceOrientation)];
}
- (IBAction)didChangeSegment:(UISegmentedControl *)control {
if (innerController) {
[innerController viewWillDisappear:NO];
[innerController.view removeFromSuperview];
[innerController viewDidDisappear:NO];
}
switch (control.selectedSegmentIndex) {
case 0:
innerController = friendsController;
self.title = #"Friends";
break;
case 1:
innerController = friendRequestsController;
self.title = #"Requests";
break;
}
[innerController viewWillAppear:NO];
[innerView addSubview:innerController.view];
[innerController viewDidAppear:NO];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[innerController viewWillAppear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.tintColor = nil;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[innerController viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[innerController viewWillDisappear:animated];
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[innerController viewDidDisappear:animated];
[super viewDidDisappear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[friendsController release], friendsController = nil;
[friendRequestsController release], friendRequestsController = nil;
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
#end
So can someone please tell me what's going on? HELP!
You need to set wantsFullScreenLayout property to YES.
in your init methods set
self.wantsFullScreenLayout = YES;
This will solve your problem.

Resources