开发者

Display a popup at the start of execution

开发者 https://www.devze.com 2023-02-03 06:44 出处:网络
When I start my iPad app, I want to display a screen that slides in on top of the main view that is there at the start up.I want this screen to take up the entire screen and display a web page, and th

When I start my iPad app, I want to display a screen that slides in on top of the main view that is there at the start up. I want this screen to take up the entire screen and display a web page, and the only way that the user can get out of it is click on a UIButton at the bottom of the screen.

Right now, 开发者_JAVA技巧I am setting the view of my main view controller as the view that I want to display, but the next step in execution is showing a UIAlert, and this alert is appearing.

What can I use to have this pop up wait for the user to click Agree before continuing?

Thanks.


You will want to use a delegate.

So to do what you want do something like this (I don't know your actual class names, so I'm guessing):

In your AlertScreenViewController.h file add this code:

@protocol AlertScreenViewControllerDelegate;
@interface AlertScreenViewController : UIViewController {
  ...
  id<AlertScreenViewControllerDelegate> delegate;
  ...
}
...
@property (assign) id<AlertScreenViewControllerDelegate> delegate;
...
@end

@protocol AlertScreenViewControllerDelegate <NSObject>
- (void)alertScreenViewControllerWillClose;
@end

Then in your AlertScreenViewController.m file:

add this:

@implementation AlertScreenViewController
...
@synthesize delegate;
...
@end

add this code wherever your button is pressed:

[self.delegate alertScreenViewControllerWillClose];

In your MainViewController.h file add this:

#import "AlertScreenViewController.h"
@interface MainViewController : UIViewController <AlertScreenViewControllerDelegate> {
...
}
...
@end

In your MainViewController.m file add this:

Wherever you've loaded up the AlertScreenViewController add this after the init call:

alertscreenviewcontroller.delegate = self;

Then move all code after the display of the alertscreenviewcontroller code to this method:

- (void) alertScreenViewControllerWillClose {
  //UIAlert logic here
}

You can find another example here: http://www.dosomethinghere.com/2009/07/18/setting-up-a-delegate-in-the-iphone-sdk/

Or just google iphone sdk delegate

0

精彩评论

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