开发者

Problem with info view on iPhone app

I am currently using this code to bring up an info view for an iPhone app.

-(IBAction)showInfo:(id)sender {
InfoView *info = [[InfoView alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
info.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:info animated:YES];
[info release];

}

And this code go back to my main view

-(IBAction) exitInfo:(id)sender {
 [self.paren开发者_如何学PythontViewController dismissModalViewControllerAnimated: YES];
}

When I run it on the simulator, it goes fine, however, on the actual iPhone, when I press the button that triggers the exitInfo method, it carries out its animation, but once it is completely off the screen and only my main view is visible, the screen will flicker, quickly showing the info view again. How can I fix this?


In my opinion, your viewController shouldn't even know it is modally viewed.

Try putting the code that send the dismissModalViewController message in your main controller and alert your main controller that the user clicked the dismiss button using a delegate.

something like this in your "parent" viewController

-(IBAction)showInfo:(id)sender {
    InfoView *info = [[InfoView alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
    info.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    info.delegate = self;
    [self presentModalViewController:info animated:YES];
    [info release];
}

-(IBAction)closedButtonClicked {
    [self dismissModalViewControllerAnimated: YES];
}

and in your "Modal" viewController

-(IBAction) exitInfo:(id)sender {
 [delegate closedButtonClicked];
}

Of course you will need a protocol like

@protocol MyCustomDelegate 
    -(IBAction)closedButtonClicked;
@end 

and something like this in your "modal" interface

-id<MyCustomDelegate> delegate;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜