PDA

View Full Version : [Resolved] Direct User to a new view with alert view




webznz
Apr 18, 2011, 08:33 PM
I am currently setting up a little security feature on this app I'm making,
whats happening as soon as my app is launched it sends its cookie to the database in return for a new cookie. If the user starts the app for the first time, or has a cookie that is out of sync because of various reasons (for instance they have given heir registration code to someone else to use) they will be given an Alert View error msg...

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device"
message:@"click OK to register"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert autorelease];
[alert show];

I am wondering how I would go about sending the user to a new view (that will allow them to enter their registration code) with the cancelButtonTitle button when it is pressed on the alert view



Shawnpk
Apr 18, 2011, 09:38 PM
I believe you have to use the UIAlertViewDelegate method(s).

jnoxx
Apr 19, 2011, 03:27 AM
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[actionSheet buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Start driving"]) {
success = [DriverService moveToNextState];
} else if ([buttonTitle isEqualToString:@"Start job"]) {
success = [DriverService moveToNextState];
} else if ([buttonTitle isEqualToString:@"Finish job"]){
success = [DriverService moveToNextState];
if (success){
[self.navigationController popViewControllerAnimated:YES];
return;
}
}
if (success){
self.driver = success;
[self updateMap];
}

}
something like this. but then with the alertView instead of actionsheet ;)

webznz
Apr 19, 2011, 03:38 PM
cheers dude :) will try it out now.

EDIT:

Im not sure if im using this correctly or not. I figure if my cancelButtonTitle:@"OK" is pressed it should initiate my alertView:didDismissWithButtonIndex: method... is that right? sorry just having abit of a moment with this.


- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//we are just checking to make sure we are getting the SML
NSString *cookieCheck = [[[NSString alloc] initWithData:cookieData encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"yum yum feed me more cookie!! %@",cookieCheck);

//Put cookie check stuff here..

//CODE=1
if([cookieCheck rangeOfString:@"Code=1"].location != NSNotFound) {
//found it Send error prompt (OK loads new view for fucnt Reg)
NSLog(@"cookieCode = code1");

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device"
message:@"click OK to register"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];

[alert autorelease];
[alert show];

}else {
NSLog(@"cookieCode = code?");
}

}

- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex {
//Test
NSLog(@"msg from alertView method");



}

webznz
Apr 19, 2011, 08:44 PM
it just clicked... made me mad as hell that i didnt think of this right away.... set delegate of the alertView to self..

Solution.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//..................
//CODE=1
if([cookieCheck rangeOfString:@"Code=1"].location != NSNotFound) {
//found it Send error prompt (OK loads new view for fucnt Reg)
NSLog(@"cookieCode = code1");


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please Register Device"
message:@"click OK to register"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];

// If i want to add text field to alert use this code....

UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];

[alert autorelease];
[alert show];

}else {
//cant find appropriate response...
NSLog(@"cookieCode = code?");
}

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {

NSLog(@"msg from alertView method");



}

jnoxx
Apr 20, 2011, 02:21 AM
But now the log is triggering on all the buttons or not?!
U need to create a buttonindex, or like in my example, compare the titles.
Greetings.

webznz
Apr 20, 2011, 03:33 PM
But now the log is triggering on all the buttons or not?!
U need to create a buttonindex, or like in my example, compare the titles.
Greetings.

Yea, I didn't do a button index because I only have the one button option. :o