开发者

UIViewController - dismissModalViewControllerAnimated issue

I'm having an issue with the dismissModalViewControllerAnimated method.

The header looks like t开发者_开发百科his:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "GADBannerView.h"
#import "weatherSetUp.h"
@interface weatherPicViewController : UIViewController{

In my viewController.m file I call

-(IBAction)didClickSetting:(id)sender{
    weatherSetUp *views = [[weatherSetUp alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:views animated:YES];
}

This all works fine, In my weatherSetUp file once the user has completed set up I was to dismiss the modal view. I do it by calling this method in the above viewController.m file:

-(void)dismissModal{

    [self.parentViewController dismissModalViewControllerAnimated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [self.parentViewController dismissModalViewControllerAnimated:NO];
    NSLog(@"Model gone!");
}

But none of these work.

This is the header file of my weatherSetUp file:

#import <UIKit/UIKit.h>
#import "viewController.h"
@interface weatherSetUp : UIViewController
-(IBAction)didClickClose:(id)sender;
@end

And the only method I've implemented is:

-(IBAction)didClickClose:(id)sender{
    NSLog(@"CLick "); 
    viewController *viewEr = [[viewController alloc] init];
    [viewEr dismissModal];
}

All the NSLog's work when I click the button, I've searched on here and tried too the above ways of dismissing it and none of them work, any ideas?


What is going wrong is you're calling dismissModal on a random view controller rather than the object that actually has the modal controller. What you'd want to do in didClickClose: is this

[[self parentViewController] dismissModalViewControllerAnimated:NO];

Also, you shouldn't be starting your class names with lowercase characters in Cocoa. They should really be capitalised and have a prefix, eg ABCWeatherSetUp. The prefix can be whatever you want, but generally you want something based on your name, your company's name or your project's name.


insted of [self.parentViewController dismissModalViewControllerAnimated:NO]; write this [self dismissModalViewControllerAnimated:NO];


Your viewEr is not the same viewController which you are trying to close, because you are creating the new object of your viewContoller.

you can create a viewContoller properties and in your viewController class file

weatherSetup.viewController = self.parentViewController;

NOTE: do not use viewContoller as a ivar, use different may name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜