iOS - UIAlertView outton - otherbutton not working as it should - ios

I'm having trouble with my app. Problem is when I press the Cancel button on the AlertView. It doesn't show the "Cancel" text that should be appearing at my output. The Confirm and Show Password buttons are working fine, both show the NSLogs, only the cancel buttons don't. Here is my code. Please be patient with me because I'm new in Xcode.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Confirm"])
{
UITextField *password = [alertView textFieldAtIndex:0];
NSLog(#"Password: %#", password.text);
if (buttonIndex != [alertView cancelButtonIndex])
{
NSLog(#"cancel");
}
else
{
NSLog(#"confirm");
entries = [[NSMutableArray alloc]init];
NSString *select = [NSString stringWithFormat:#"SELECT * FROM summary2 WHERE username = '%s' and pass = '%s'",[self.lbUser.text UTF8String],[password.text UTF8String]];
sqlite3_stmt *statement;
if (sqlite3_prepare(user, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
{
if(sqlite3_step(statement)==SQLITE_ROW)
{
NSLog(#"database updated");
[self updatedatabase];
UIAlertView *alert3 = [[UIAlertView alloc]initWithTitle:#"Done" message:#"Account was updated successfully!" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert3 show];
}
else
{
NSLog(#"Authentication Failed!");
UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:#"Failed" message:#"Wrong Password! Account was not updated." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert2 show];
NSLog(#"fail");
}
}
}
}
else if([title isEqualToString:#"View Password"])
{
UITextField *password = [alertView textFieldAtIndex:0];
NSLog(#"Password: %#", password.text);
if (buttonIndex != [alertView cancelButtonIndex])
{
NSLog(#"cancel");
}
else
{
NSLog(#"confirm");
entries = [[NSMutableArray alloc]init];
NSString *select = [NSString stringWithFormat:#"SELECT * FROM summary2 WHERE username = '%s' and pass = '%s'",[self.lbUser.text UTF8String],[password.text UTF8String]];
sqlite3_stmt *statement;
if (sqlite3_prepare(user, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
{
if(sqlite3_step(statement)==SQLITE_ROW)
{
NSLog(#"database updated");
[self switchbtn];
}
else
{
//switch1.on=YES;
NSLog(#"Authentication Failed!");
UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:#"Failed" message:#"Wrong Password! Cannot view password." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert2 show];
NSLog(#"fail");
}
}
}
}
}

According to your if,if-else statements you're only looking for "View Password" and "Confirm" buttons. There is no branch in your if-statement to examine the cancel button.

Related

when I Deactivate the user then i want to drop the sqlite(remove the user from sqlite)

When the User Deactivate the UsersID then i would like to to drop user from the sqlite(remove the user from sqlite)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {
//Deactivate account
NSLog(#"selected delete Account");
BOOL success=[self DeletingAccount];
if (success==YES) {
[self dropTable];
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Successfull" message:#"Your account was deleted successfully" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
//After the account is deleted navigation to login view controller
ViewController *controller=[self.storyboard instantiateViewControllerWithIdentifier:#"vc"];
[self.navigationController pushViewController:controller animated:YES];
} else {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Unsuccessfull" message:#"Your account was not deleted try again" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
else {
//Insert the code here to change user's number
NSLog(#"selected Change Number");
}
}
-(void)dropTable
{
//[SSWriteReadInDb deleteAllRousInQuotesTable];
sqlite3 *database;
NSString *databasePath=[SSSQLite pathToDB];
if (sqlite3_open([databasePath UTF8String], &database)==SQLITE_OK) {
const char *sqlStatement="DROP table QuotesTable";
char *errMsg;
if (sqlite3_exec(database, sqlStatement, NULL, NULL, &errMsg)) {
NSLog(#"Table dropped");
}
sqlite3_close(database);
} else {
NSLog(#"Failed to open db");
}
}

Multiple UIAlertViews to Enter Data

I have two buttons that will pop up an alertview with textfield to input data. However, only certain characters are allowed in each of the two textfields. Somehow, if I press the second button, the character set from the first button is used. What's going on here?
Also, what would be a more elegant form of inputting data without having to use an alertview? Could I use a modal view? If so, how?
- (IBAction)editRate
{
if(!self.powerOn) return;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Edit Jail Fee Rate"
message:#"Enter New Daily Rate"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
UITextField *field = [alertView textFieldAtIndex:0];
field.placeholder = #"Enter New Rate";
NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:#"0123456789."] invertedSet];
if ([field.text rangeOfCharacterFromSet:set].location != NSNotFound)
{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Only numbers are allowed in this field."delegate:self cancelButtonTitle:#"OK"otherButtonTitles:nil];
[errorAlert show];
FeeRate.text=#"0.00";
}
else
{
FeeRate.text = field.text;
[[NSUserDefaults standardUserDefaults] setObject:field.text forKey:RATE_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
else
{
}
}
- (IBAction)editDate
{
if(!self.powerOn) return;
UIAlertView *alertDate = [[UIAlertView alloc] initWithTitle:#"Edit Jail Fee Date"
message:#"Enter New Date"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
alertDate.alertViewStyle = UIAlertViewStylePlainTextInput;
[[alertDate textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[alertDate show];
}
- (void)alertDate:(UIAlertView *)alertDate clickedButtonAtIndex:(NSInteger)buttonIndex2
{
if (buttonIndex2 != alertDate.cancelButtonIndex)
{
UITextField *fieldDate = [alertDate textFieldAtIndex:0];
fieldDate.placeholder = #"Enter New Date";
NSCharacterSet * setnew = [[NSCharacterSet characterSetWithCharactersInString:#"0123456789/"] invertedSet];
if ([fieldDate.text rangeOfCharacterFromSet:setnew].location != NSNotFound)
{
UIAlertView *errorAlert1 = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Only numbers and slashes are allowed in this field."delegate:self cancelButtonTitle:#"OK"otherButtonTitles:nil];
[errorAlert1 show];
FeeDate.text=#"00/00/0000";
}
else
{
FeeDate.text = fieldDate.text;
[[NSUserDefaults standardUserDefaults] setObject:fieldDate.text forKey:DATE_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
else
{
}
}
When a UIAlertView is dismissed then a function called
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
is called.
So, both your alert views call this function.
One way to tell which alertView is calling it, you could create an ivar or better two properties like this:
#property (nonatomic, strong) UIAlertView *rateAlert;
#property (nonatomic, strong) UIAlertView *dateAlert;
and you should initialize like this:
[self setRateAlert:[[UIAlertView alloc] initWithTitle...
[self.rateAlert show];
and
[self setDateAlert:[[UIAlertView alloc] initWithTitle...
[self.dateAlert show];
and then:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView==self.rateAlert) {
//do whatever for rateAlert
} else {
//do whatever with dateAlert
}
}

UIAlertView IndexButton

I have this code right here for annotations in my map...
//alert view
if ([ann.title isEqual: #"Al-saidiya"]) {
NSString *msg=#"Phone No : 079011111";
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"Call Us", nil];
[alert1 show];
}
else if ([ann.title isEqual: #"Al-Kadmiya"]) {
NSString *msg=#"Phone No : 07902222222";
UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"ok" otherButtonTitles:#"Call Us", nil];
[alert2 show];
}
else if ([ann.title isEqual: #"Palestine St"]) {
NSString *msg=#"Phone No : 0790333333";
UIAlertView *alert3 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"ok" otherButtonTitles: #"Call Us",nil];
[alert3 show];
}
else if ([ann.title isEqual: #"Karada Maryam"]){
NSString *msg=#"Phone No : 07905867";
UIAlertView *alert4 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"ok" otherButtonTitles:#"Call Us", nil];
[alert4 show];
}
else if ([ann.title isEqual: #"Mansour Office"]) {
NSString *msg=#"Phone No : 07954212";
UIAlertView *alert5 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"ok" otherButtonTitles: #"Call Us",nil];
[alert5 show];
}
else if ([ann.title isEqual: #"Hunting Club"]) {
NSString *msg=#"Phone No : 079337745";
UIAlertView *alert6 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"ok" otherButtonTitles: #"Call Us",nil];
[alert6 show];
}
else if ([ann.title isEqual: #"Al-jadriya"]) {
NSString *msg=#"Phone No : 07976231";
UIAlertView *alert7 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"ok" otherButtonTitles: #"Call Us",nil];
[alert7 show];
}
else if ([ann.title isEqual: #"Al-jamea'a"]) {
NSString *msg=#"Phone No : 07865323";
UIAlertView *alert8 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"ok" otherButtonTitles: #"Call Us",nil];
[alert8 show];
}
}
And when i apply this method ::
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex==1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"telprompt://576576576"]]];
NSLog(#"It works!");
}
}
it has been applied on every alert objects above there and took the same number.i want every alert object to get its own phone number when i want to call.
Just add a tag to your alert views
if ([ann.title isEqual: #"Al-saidiya"]) {
NSString *msg=#"Phone No : 079011111";
UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:#"Contact" message:msg delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"Call Us", nil];
alert1.tag = 0; // <--
[alert1 show];
}
and check the tag in alertView:clickedButtonAtIndex::
if (alertView.tag == 0) {
// call Al-saidiya
}
...
Well even if the solution proposed by tilo works, I think is not the right approach when you have multiple instances of objects like UIAlertview.
I would like to suggest you to use blocks instead.
These categories (the project use the same pattern for UIActionSheet) allow you to bind an action block to a specific button in your alertView.
Using this approach you can get rid of all the if/switch statements using the delegate pattern.
As the title and the phone number is a 1:1 relationship I'd use a dictionary:
NSDictionary *titlesAndMessages = #{#"Al-saidiya" : #"Phone No : 079011111",
#"Al-Kadmiya" : #"Phone No : 07902222222",
#"Palestine St" : #"Phone No : 0790333333"};
...
NSString *messageString = nil;
for (NSString *keyTitle in [titlesAndMessages allKeys]) {
if ([ann.title isEqualToString:keyTitle]) {
messageString = [titlesAndMessages objectForKey:keyTitle];
break;
}
}
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Contact" message:messageString delegate:self cancelButtonTitle:#"ok" otherButtonTitles:#"Call Us", nil];
[alert show];
}
This scales a lot better as you won't have to write any additional code to expand, just add entries to the dictionary (automagically or otherwise).
Using UIAlertViewDelegate is really clumsy. I recommend everyone use PSAlertView for any non-trivial use of alerts.
Using this, the code becomes simple and self contained.
- (void)promptToContact:(NSString *)message
withNumber:(NSString *)phoneNumber
{
PSAlertView *alert = [[PSAlertView alloc] initWithTitle:#"Contact"];
[alert setCancelButtonWithTitle:#"Dismiss" block:^{}];
[alert addButtonWithTitle:#"Call" block:^{
NSString *urlString = [NSString stringWithFormat:#"telprompt://%#", phoneNumber];
NSURL *url = [NSURL urlWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}];
[alert show];
}
First set the tag in your alertview in above code then in your below method. Try like this:-
-(void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex
{
int indexValue=alertView.tag;
switch (indexValue)
{
case 0:
NSLog (#"zero");
//your code
break;
case 1:
NSLog (#"one");
//your code
break;
case 2:
NSLog (#"two");
//your code
break;
case 3:
NSLog (#"three");
// your code
break;
case 4:
NSLog (#"four");
//your code
break;
case 5:
NSLog (#"five");
// your code
break;
...... Up to
case 8:
// your code
break;
default:
NSLog (#"done");
break;
}

UIAlertView keeps re-appearing after dismissWithClickedButtonIndex included in performSelector: withObject: afterDelay:

I have a button which I want to implement with password before triggering a segue if the password is correct. it all looks fine up to the moment when you type in wrong password and I have implemented another alertView to tell the user the password is wrong. When the alert view pops out and dismisses after some delay, it keeps re-appearing and disappearing and nothing else can be done on the screen!
How to stop the re appearing?
Below is my part of the code that deals with this:
- (IBAction)editLeagues:(id)sender {
[self presentAlertViewForPassword];
}
-(void)presentAlertViewForPassword
{
_passwordAlert = [[UIAlertView alloc]initWithTitle:#"Password"
message:#"Enter Password to edit Leagues"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[_passwordAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
_passwordField = [_passwordAlert textFieldAtIndex:0];
_passwordField.delegate = self;
_passwordField.autocapitalizationType = UITextAutocapitalizationTypeWords;
_passwordField.tag = textFieldPassword;
[_passwordAlert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSString *password = [NSString stringWithFormat:#"55555"];
if ( ![_passwordField.text isEqual:password]) {
_wrongPassword = [[UIAlertView alloc] initWithTitle:#"Wrong Password"
message:#"You are not authorised to use this feature!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
[_wrongPassword show];
[self performSelector:#selector(allertViewDelayedDissmiss:) withObject:nil afterDelay:2];
}
else
{
[self performSegueWithIdentifier:#"addLeague" sender:[alertView buttonTitleAtIndex:0]];
}
}
-(void) allertViewDelayedDissmiss:(UIAlertView *)alertView
{
[_wrongPassword dismissWithClickedButtonIndex:-1 animated:YES];
}
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
NSString *inputText = [[alertView textFieldAtIndex:0] text];
if( [inputText length] >= 4 )
{
return YES;
}
else
{
return NO;
}
}
[_wrongPassword dismissWithClickedButtonIndex:-1 animated:YES]; will call the delegate method alertView:didDismissWithButtonIndex:
You have two options:
don't set a delegate on the wrong password alert
check for the correct alert in alertView:didDismissWithButtonIndex: e.g.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (alert == _passwordAlert) {
NSString *password = [NSString stringWithFormat:#"55555"];
// and so on
}
}
Issue is causing because when you dismiss the wrong password alert it'll also call the didDismissWithButtonIndex delegate method.
Solution 1
Set the delegate of wrong password alert to nil.
wrongPassword = [[UIAlertView alloc] initWithTitle:#"Wrong Password"
message:#"You are not authorised to use this feature!"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
Solution 2
Add a tag to your alertView. And change your methods like:
-(void)presentAlertViewForPassword
{
_passwordAlert = [[UIAlertView alloc]initWithTitle:#"Password"
message:#"Enter Password to edit Leagues"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[_passwordAlert setAlertViewStyle:UIAlertViewStyleSecureTextInput];
passwordAlert.tag = 7;
_passwordField = [_passwordAlert textFieldAtIndex:0];
_passwordField.delegate = self;
_passwordField.autocapitalizationType = UITextAutocapitalizationTypeWords;
_passwordField.tag = textFieldPassword;
[_passwordAlert show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(alertView.tag == 7)
{
NSString *password = [NSString stringWithFormat:#"55555"];
if ( ![_passwordField.text isEqual:password])
{
_wrongPassword = [[UIAlertView alloc] initWithTitle:#"Wrong Password"
message:#"You are not authorised to use this feature!"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
[_wrongPassword show];
[self performSelector:#selector(allertViewDelayedDissmiss:) withObject:nil afterDelay:2];
}
else
{
[self performSegueWithIdentifier:#"addLeague" sender:[alertView buttonTitleAtIndex:0]];
}
}
}

validate multi uitextfield

I use this code to check if text fields are empty or not. The first time, it will work, but when I change the text field values, the alert does not works.
-(void)sendclick {
NSString *msg;
if(firstnametextfield.text==NULL) {
msg=#"enter first name";
NSLog(#"%#",firstnametextfield.text);
}
else if(lastnametextfield.text==NULL) {
msg=#"enter last name";
NSLog(#"%#",lastnametextfield.text);
}
else if(emailtextfield.text==NULL) {
msg=#"enter email address";
NSLog(#"%#",emailtextfield.text);
}
else if(companytextfield.text==NULL) {
msg=#"enter company name";
NSLog(#"%#",companytextfield.text);
}
else if(phonetextfield.text==NULL) {
msg=#"enter phone numper";
NSLog(#"%#",phonetextfield.text);
}
else {
msg=#"register success fully";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
}
}
There are a couple of things to consider about this code:
As others have pointed out, this is not the correct way to check for an empty string.
a. First, if you do want to check for a string that is not allocated, you should be checking for nil and not NULL.
b. Secondly, the string could also be allocated, but have no characters, so you should check to see if it is an empty string as well.
c. Note that you typically want to check BOTH of those conditions, and do the same thing, because, usually, there is no difference between a string that is nil and one that is empty as far as the business logic is concerned.
d. The easiest way to do this is to simply check the length of the string. This works, because if a message is sent to a nil object, it will return 0, and if it is an actual string with no characters, it will also return 0.
Therefore, a check similar to this would work instead:
if([firstnametextfield.text length] == 0)
You typically do not want to check the value of a text field directly like this for form validation. This is because, under certain situations (like when a text field is in a table view cell and scrolls off of the screen) the text field is not available and you won't have access to the data stored in the text field.
Instead, you should collect the text immediately after it is entered by setting the delegate of the text field to your view controller and implementing the following function:
- (void)textFieldDidEndEditing:(UITextField *)textField {
if (textField == firstnametextfield) {
// Store the first name in a property, or array, or something.
}
}
Then, when you are ready to validate the entered information, check the values that you have stored instead of the actual text field values themselves, using the technique from #1 above.
You shouldn't compare the text field value with NULL. Rather, compare it with #"". You can also trim whitespace characters too:
[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- (BOOL)isEmptyOrNull:(NSString*)string {
if (string) {
if ([string isEqualToString:#""]) {
return YES;
}
return NO;
}
return YES;
}
-(void)sendclick {
NSString *msg;
if([self isEmptyOrNull:firstnametextfield.text]) {
msg=#"enter first name";
NSLog(#"%#",firstnametextfield.text);
}
.....
.....
.....
Try using
if([lastnameTextField.text isEqualToString:#""])
{
msg = #"Enter last name";
NSLog(#"%#",lastnametextfield.text);
}
This is how you check if a NSString is empty or not.
You can't compare string objects using the == or != operators. So here is the correct one:
-(void)sendclick
{
NSString *msg;
if([firstnametextfield.text isEqualToString:#""])
{
msg=#"enter first name";
NSLog(#"%#",firstnametextfield.text);
}
else
if([lastnametextfield.text isEqualToString:#""])
{
msg=#"enter last name";
NSLog(#"%#",lastnametextfield.text);
}
else if([emailtextfield.text isEqualToString:#""])
{
msg=#"enter email address";
NSLog(#"%#",emailtextfield.text);
}
else if([companytextfield.text isEqualToString:#""])
{
msg=#"enter company name";
NSLog(#"%#",companytextfield.text);
}
else if([phonetextfield.text isEqualToString:#""])
{
msg=#"enter phone numper";
NSLog(#"%#",phonetextfield.text);
}
else
{
msg=#"register success fully";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
[alert release];
}
}
I hope that helps you.
-(void)sendclick
{
if ([self ControlValidation]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sucess" message:#"Registration done successfully" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
-(BOOL)ControlValidation
{
if ([self isEmpty:firstnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:lasttnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
return YES;
}
-(BOOL)isEmpty:(NSString *)str
{
if (str == nil || str == (id)[NSNull null] || [[NSString stringWithFormat:#"%#",str] length] == 0 || [[[NSString stringWithFormat:#"%#",str] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0)
{
return YES;
}
return NO;
}
-(void)validateTextFields
{
if ([self Validation]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sucess" message:#"Registration done successfully" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
-(BOOL)Validation
{
if ([self isEmpty:firstnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:lasttnametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:Usernametextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:phonetextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
if ([self isEmpty:emailtextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"First Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
if ([self isEmpty:passwordtextfield.text ]==YES)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"Last Name is empty" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return NO;
}
}
return YES;
}
-(BOOL)isEmpty:(NSString *)str
{
if (str == nil || str == (id)[NSNull null] || [[NSString stringWithFormat:#"%#",str] length] == 0 || [[[NSString stringWithFormat:#"%#",str] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0)
{
return YES;
}

Resources