SRL Archive - Help

Objective C Help


Jim

2012-07-05 16:05:03

I need help with Objective C. In this case I've created a UIAlertView with UIAlertViewStyleLoginAndPasswordInput style and I want to be able to check if the login data is correct, but I don't know how to check it after a button has been pressed.


- (IBAction)loginPushed:(id)sender
{
UIAlertView *loginAlert = [[UIAlertView alloc]initWithTitle:@"Login to BindingDB" message:@"Enter your login info" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
[loginAlert addButtonWithTitle:@"Enter"];
[loginAlert addButtonWithTitle:@"Cancel"];
[loginAlert show];
[self checkLogin:loginAlert];
}

- (void)checkLogin:(UIAlertView *)loginAlert
{
//I don't know what to put in this if statement to make it work only when the "enter" button has been pressed
if () {
NSString *login = [[loginAlert textFieldAtIndex:0] text];
NSString *password = [[loginAlert textFieldAtIndex:1] text];
if (login == @"Jim" && password == @"Password") {
[self verifyLogin:true];
}
else {
[self verifyLogin:false];
}
}
}

- (void)verifyLogin:(BOOL)checkLogin {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
if (checkLogin) {
[alert setTitle:@"Login Successful"];
[alert setMessage:@"You have logged in"];
}
else {
[alert setTitle:@"Login Failed"];
[alert setMessage:@"Try Again"];
}

[alert show];
}

Silentcore

2012-07-05 16:09:06

why not post it here so people who take a look at this thread, can see the code and see it and that might help you out a bit more then just reading words..

Jim

2012-07-05 16:11:12

From: Ucantseemebot
why not post it here so people who take a look at this thread, can see the code and see it and that might help you out a bit more then just reading words..


Objective C isn't that popular of a language, don't know if too many SRL people would know it.

Silentcore

2012-07-05 16:12:45

From: Liimujx
Objective C isn't that popular of a language, don't know if too many SRL people would know it.


and you wont get any help if you dont post here..you never know if someone takes a look at the thread and decides to help you out bro..

Brandon

2012-07-05 16:42:26

Why is everything commented out :S? Use CodeTags or do:



Remove the spaces in the tags.

Jim

2012-07-05 16:54:58

From: Brandon
Why is everything commented out :S? Use CodeTags or do:



Remove the spaces in the tags.


Ok I changed it. Could you help me with this?

Brandon

2012-07-05 17:13:32

Well I won't be able to full write all the code for you since I no longer have my mac or hackintosh (Testing Windows 8 atm).

But I can tell you that you need to check which sender is giving you the msg.

Delegate UIAlertview and iit's implementation should be:


- (void)checkLogin:(UIAlertView *)loginAlert clickedButtonAtIndex:(NSInteger)BtnIndex
{
if (BtnIndex == 0) //You can also use a switch case here and switch on whatever button index.
{
//Validate the login.
}
else if (BtnIndex == 1)
{
//Cancel login.
}
}

TBH this is busting my balls right now lol. It's been forever!! Since I touched iPhone development. I honestly hope that helps; Sat here for a good 3-5 mins thinking hard.. Really hard without a compiler to test.

Jim

2012-07-05 17:47:56

From: Brandon
Well I won't be able to full write all the code for you since I no longer have my mac or hackintosh (Testing Windows 8 atm).

But I can tell you that you need to check which sender is giving you the msg.

Delegate UIAlertview and iit's implementation should be:


- (void)checkLogin:(UIAlertView *)loginAlert clickedButtonAtIndex:(NSInteger)BtnIndex
{
if (BtnIndex == 0) //You can also use a switch case here and switch on whatever button index.
{
//Validate the login.
}
else if (BtnIndex == 1)
{
//Cancel login.
}
}

TBH this is busting my balls right now lol. It's been forever!! Since I touched iPhone development. I honestly hope that helps; Sat here for a good 3-5 mins thinking hard.. Really hard without a compiler to test.


Thanks, I did what you did and delegated it, and it almost works, I'm just gonna try some new stuff to make it so it only applies to that alert view and not any others I create.

Tniffoc

2012-07-05 18:09:57

I think this is the protocol that you're looking for. This should tell you everything that you needed to know. I'm an iPhone dev, but most people here at SRL are not.

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html#//apple_ref/doc/uid/TP40007548