This is my code:
#import "RootViewController.h"
@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor blackColor];
UIWebView *webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://deathsrepo.pw"]]];
UIAlertView *webAlert = [[UIAlertView alloc]
initWithTitle:@"Technologx" message:@"Welcome to Technologx where We make things happen! If your new to the forum please create a account. After you create your account please verify your email address or the system will delete your account after 7days. Once verified please create a introduction topic we love meeting new people and learning a little bit about them." delegate:self cancelButtonTitle:@"Done" otherButtonTitles:@"OK", nil];
[webAlert show];
[webAlert release];
}
@end
How can I make my AlertView window only show up once. I want the user to be able to press 'OK' and it won't popup when they open the app again but if they just press "done" it will?
First, alert view is deprecated. Use an alert controller as shown below. Second, switch around where you are placing your code. I would recommend loading the web view in viewDidLoad:
, but for the sake of simplicity let's stay with this.
- (void)viewDidAppear:(BOOL)animated {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor blackColor];
UIWebView *webView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://deathsrepo.pw"]]];
if([[NSUserDefaults standardUserDefaults] boolForKey:@"firstKey"]!=YES) {
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Technologx"
message:@"Welcome to Technologx where We make things happen! If your new to the forum please create a account. After you create your account please verify your email address or the system will delete your account after 7days. Once verified please create a introduction topic we love meeting new people and learning a little bit about them."
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
}
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[[NSUserDefaults standardUserDefaults] setBOOL:YES forKey:@"firstKey"];
}];
[webAlert release];
}
@end
Let's talk about what we're doing. We check if user defaults key is nil, and if it is, show them the sheet. If they have ever clicked OK on the sheet, meaning they've seen it before, we setup a handler that will add any ol' thing to the key. Hence, the key is not nil ever again, so your sheet will never appear again once they've seen it.