So i have this piece of code in my TVC
-(void)getCats {
[HUD showAnimated:YES whileExecutingBlock:^{
catArray = [menuPost getCategories];
} completionBlock:^{
if(catArray == nil){
[[[UIAlertView alloc] initWithTitle:#"Oops!" message:#"Hubo un problema intente mas tarde" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
}
}];
}
i placed some break points and i noticed that i doesn't execute the method right away it jumps to
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return catArray.count;
}
so the problem is that since it skips this line of code(below) the numberOfRows is 0 and this method returns an NSMutableArray after making a post it wouldn't display the objects
catArray = [menuPost getCategories];
your code is fine , you are not refresh your table
-(void)getCats {
[HUD showAnimated:YES whileExecutingBlock:^{
catArray = [menuPost getCategories];
} completionBlock:^{
if(catArray == nil){
[[[UIAlertView alloc] initWithTitle:#"Oops!" message:#"Hubo un problema intente mas tarde" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil] show];
// if your array count ==0 , hidden the table
[yourtableviewname setHidden:YES];
}
else
{
// if your array count !=0 , open the table, and reload/refresh the table
[yourtableviewname setHidden:NO];
[yourtableviewname reloadData];
}
}];
}
Related
I am new in objective C.Execute this Program ON Clicking on button"Click here to sell your Gold now"
It will lunch you to dashboard.In dashboard select Transaction History.I have fetchNewHothistory function in TransactionHistoryViewController.m file responsible for fetching data from url and displaying it onto the viewcontroller file
-(void)fetchNewHothistory
{
NSTimer *t = [NSTimer scheduledTimerWithTimeInterval:1.0
target: self
selector:#selector(mytimerChecking:)
userInfo: nil repeats:NO];
NSMutableDictionary *paramDict=[NSMutableDictionary dictionary];
[paramDict setObject:#"ios" forKey:#"request"];
[paramDict setObject:[NSString stringWithFormat:#"%#",currentUser.user_id] forKey:#"user_id"];
[paramDict setObject:[NSString stringWithFormat:#"%#",self.currentLimitNew] forKey:#"limit_start"];
[GeneralWebservices webserviceMainSplashCall:paramDict webserviceName:Webservice_TransactionHistory OnCompletion:^(id returnDict, NSError *error) {
if ([returnDict[#"success"] intValue] ==1)
{
// UIAlertView* alert = [[UIAlertView alloc] init];
// [alert setTitle:#"RECORD FOUND"];
// // [alert setMessage:returnDict[#"message"]];
// [alert addButtonWithTitle:#"OK"];
// [alert show];
[history addObjectsFromArray:returnDict[#"data"]];
self.currentLimitNew=[NSString stringWithFormat:#"%#",returnDict[#"limit_start"]] ;
[historyTableView reloadData];
}
else
{
UIAlertView* alert = [[UIAlertView alloc] init];
[alert setTitle:#"RECORD FOUND"];
//[alert setMessage:returnDict[#"message"]];
[alert addButtonWithTitle:#"OK"];
[alert show];
}
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
[historyTableView.pullToRefreshView stopAnimating];
[historyTableView.infiniteScrollingView stopAnimating];
}];
}
Issue -1
Record found but nothing displayed on Viewcontroller on selecting the Transaction History.The How to display record onto viewcontroller?
Issue -2
In on selecting Profile the ProfileViewController.m is executed .On updating the user profile .It does not updates .It remain buffering .How to perform profile update .
you can download the project from this link .https://drive.google.com/file/d/1daW4veZAI21b8TqKFHauSFTboHKJceaG/view?usp=sharing
Try this:
dispatch_async(dispatch_get_main_queue(), ^{
[historyTableView reloadData];
});
I have a login page with username,password textfield and a submit button.
If the focus is on password textfield and the user presses the submit button without pressing the return key on keyboard.
The keyboard is dismissed as i uses resignFirstResponder to dismiss the keyboard but when i hit the server and the alert comes of invalid credentials,then within nano seconds when alert is shown,keyboard also appears.
Used the below line of code to dismiss keyboard on Login Button click.
[self.passwdTxtFld setDelegate:self];
[self.usernameTxtFld setDelegate:self];
[self.view endEditing:YES];
Below is the code from where i get the response from server and also displays the alert.
- (void)checkLogin
{
NSLog(#"???%#",self.usernameTxtFld.text);
NSDictionary *checkLogin=[pwInteract initializeWithOrgId:#"JVVC" AppId:#"JVVC" LoginId:self.usernameTxtFld.text Password:self.passwdTxtFld.text];
NSLog(#"checklogin is %#",checkLogin);
if(checkLogin)
{
if(![[checkLogin objectForKey:#"NOTIFICATION"]isEqualToString:#"Y"] && ![[checkLogin objectForKey:#"NOTIFICATION"]isEqualToString:#"NV"]){
[loggingInAlert dismissWithClickedButtonIndex:loggingInAlert.cancelButtonIndex animated:YES];
[loggingInAlert removeFromSuperview];
NSLog(#"?? response is %#",checkLogin);
NSString *result = [checkLogin objectForKey:#"IS_AUTH"];
NSString *error = [checkLogin objectForKey:#"ERROR"];
if ([result isEqualToString:#"Y"] )
{
if([self.usernameTxtFld.text isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:#"username"]]){
[[NSUserDefaults standardUserDefaults] setObject:#"olduser" forKey:#"usertype"];
}
else{
[[NSUserDefaults standardUserDefaults] setObject:#"newuser" forKey:#"usertype"];
}
[[NSUserDefaults standardUserDefaults]setObject:#"" forKey:#"fetch"];
[[NSUserDefaults standardUserDefaults]setObject:#"" forKey:#"state"];
[[NSUserDefaults standardUserDefaults]setObject:#"success" forKey:#"state"];
[[NSUserDefaults standardUserDefaults]setObject:self.usernameTxtFld.text forKey:#"username"];
[self performSegueWithIdentifier:#"success" sender:nil];
}
else if (![error isEqualToString:#""])
{
UIAlertView *networkAlertView = [[UIAlertView alloc] initWithTitle:#"Error" message:error delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
networkAlertView.tag = 1;
[networkAlertView show];
[self.view endEditing:YES];
if([self.passwdTxtFld isFirstResponder]){
NSLog(#"pass");
}
if([self.usernameTxtFld isFirstResponder]){
NSLog(#"ddd");
}
}
else if ([result isEqualToString:#""])
{
NSString *error = [checkLogin objectForKey:#"ERROR"];
UIAlertView *networkAlertView = [[UIAlertView alloc] initWithTitle:#"Error" message:error delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
networkAlertView.tag = 3;
[networkAlertView show];
}
else
{
UIAlertView *networkAlertView = [[UIAlertView alloc] initWithTitle:#"" message:#"Oops! Either Username or Password is incorrect. Please type correct Username and Password to proceed." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
networkAlertView.tag = 3;
[networkAlertView show];
}
}
else if([[checkLogin objectForKey:#"NOTIFICATION"]isEqualToString:#"NV"]){
[customAlert hideActivityIndicator];
}
}
else
{
UIAlertView *networkAlertView = [[UIAlertView alloc] initWithTitle:#"Server Error" message:#"No Response From Server." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
networkAlertView.tag = 3;
[networkAlertView show];
}
}
On click event of login button have resigned both the username and password textfield,also the UITextFieldDelegate are connected.
Mistake:-
According to your code you are just resigning your keyboard in one "else if" condition:-
else if (![error isEqualToString:#""])
{
UIAlertView *networkAlertView = [[UIAlertView alloc] initWithTitle:#"Error" message:error delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
networkAlertView.tag = 1;
[networkAlertView show];
[self.view endEditing:YES];
What about the others else if condition, Things will be resolved if you resign keyboard [self.view endEditing:YES] in the very first statement of (void)checkLogin method.
Try [self.view endEditing:YES] when you tap login button or just before you show alert.
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self view] endEditing:YES];
}
or try
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return YES;
}
// It is important for you to hide the keyboard
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
Also check UITextFieldDelegate delegate method
When I click on a button in one row, the button in a different row disappears. Why might this be happening?
I looked at the following question and all the other questions within it, but nothing really answers my issue.
Custom, Imageless UIButton title disappears
I used the Debug Color Blended Layers to see if it's just a color thing, but my button just appears to disappear completely. I suspected this was a button.hidden property thing so I hardcoded button.hidden = NO; but nothing has changed.
What went wrong here?
Table Control Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([locationObjectsArray count] > 0)
{
return [locationObjectsArray count]+1;
}
else
return 1;
}
// Populate the Table View with member names
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier= #"Cell";
UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the Cell...
UIButton *selectButton = (UIButton *)[cell viewWithTag:1];
UILabel *cityNamesText = (UILabel *)[cell viewWithTag:2];
UIButton *editButton = (UIButton *)[cell viewWithTag:3];
//NSLog(#"[locationObjectsArray count]: %lu", (unsigned long)[locationObjectsArray count]);
if (indexPath.row >= [locationObjectsArray count]) {
// locationObjectsArray count == 0; Empty Array
cityNamesText.text = #"Add New Location";
NSLog(#"%ld: %#", (long)indexPath.row, #"Add New Location");
editButton.hidden = NO;
[editButton setTitle:#"Add" forState:UIControlStateNormal];
//[editButton setTitle:#"Add" forState:UIControlStateApplication];
selectButton.hidden = YES;
}
else if ([locationObjectsArray count] > 0) {
LocationObject *locObject = [locationObjectsArray objectAtIndex:indexPath.row];
NSLog(#"%ld: %#", (long)indexPath.row, [locObject getLocationName]);
cityNamesText.text = [locObject getLocationName];
selectButton.hidden = NO;
editButton.hidden = NO;
}
// Assign button tags
selectButton.tag = indexPath.row;
editButton.tag = indexPath.row;
[selectButton addTarget:self action:#selector(selectButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[editButton addTarget:self action:#selector(editButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
LocationObject *selectedLocationObject = [self loadLocationObjectWithKey:#"locObject"];
// Set Selected Cell to different Color
if ([cityNamesText.text isEqualToString:[selectedLocationObject getCityName]]) {
// Change to lightBlue color
UIColor * lightBlue = [UIColor colorWithRed:242/255.0f green:255/255.0f blue:254/255.0f alpha:1.0f];
[cell setBackgroundColor:lightBlue];
}
else
{
// All non-selected cells are white
//[cell setBackgroundColor:[UIColor whiteColor]];
//editButton.hidden = NO;
}
return cell;
}
// Select Button Clicked method
-(void)selectButtonClicked:(UIButton*)sender
{
if ([locationObjectsArray count] == 0)
{
NSLog(#"locObject count == 0");
// locationObjectsArray count == 0; Empty Array
// City name input is invalid
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"No Locations Set"
message:#"Please add a new location."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
else
{
NSLog(#"locObject count > 0");
if (sender.tag >= locationObjectsArray.count) {
// Create local isntance of the selected locationObject
LocationObject *locObject = [locationObjectsArray objectAtIndex:sender.tag];
// Set locObject as current default locObject
[self saveLocationObject:locObject key:#"locObject"];
}
[mainTableView reloadData];
}
}
// Edit Button Clicked method
-(void)editButtonClicked:(UIButton*)sender
{
if ([locationObjectsArray count] == 0) {
// locationObjectsArray count == 0; Empty Array
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"Add Location"
message:#"Input City Name"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert addButtonWithTitle:#"Save"];
[alert show];
}
else
{
selectedObjectInArray = sender.tag;
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"Edit Location"
message:#"Input City Name"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert addButtonWithTitle:#"Save"];
[alert show];
}
}
// Handle alertView
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if ([alertView.title isEqualToString:#"Add Location"]) {
// Add Location Alert View
if (buttonIndex == 0)
{
NSLog(#"You have clicked Cancel");
}
else if(buttonIndex == 1)
{
NSLog(#"You have clicked Save");
UITextField *cityNameTextField = [alertView textFieldAtIndex:0];
NSString *saveLocationName = cityNameTextField.text;
NSLog(#"saveLocationName: %#", saveLocationName);
if ([self isLocationValid:saveLocationName] == YES) {
NSLog(#"location is valid. locationObjectsArray.count = %lu", locationObjectsArray.count);
if (locationObjectsArray.count == 0) {
locationObjectsArray = [NSMutableArray array];
}
// City name input is valid
LocationObject *locObject = [[LocationObject alloc] init];
[locObject setCityName:saveLocationName];
locObject.byCityName = YES;
[locationObjectsArray addObject:locObject];
NSLog(#"After addObject: locationObjectsArray.count = %lu", locationObjectsArray.count);
[self saveLocationArrayObject:locationObjectsArray key:#"locationObjectsArray"];
[mainTableView reloadData];
}
else
{
// City name input is invalid
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"City Name Invalid"
message:#"Unable to locate input city."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
}
}
else if ([alertView.title isEqualToString:#"Edit Location"])
{
// Edit Location Alert View
if (buttonIndex == 0)
{
NSLog(#"You have clicked Cancel");
}
else if(buttonIndex == 1)
{
NSLog(#"You have clicked Save");
UITextField *cityNameTextField = [alertView textFieldAtIndex:0];
NSString *saveLocationName = cityNameTextField.text;
if ([self isLocationValid:saveLocationName]) {
// City name input is valid
int selectedIndex = (int)selectedObjectInArray;
LocationObject *locObject = [locationObjectsArray objectAtIndex:selectedIndex];
[locObject setCityName:saveLocationName];
[locObject setByCityName:(Boolean *)TRUE];
[locationObjectsArray setObject:locObject atIndexedSubscript:selectedIndex];
[self saveLocationArrayObject:locationObjectsArray key:#"locationObjectsArray"];
[mainTableView reloadData];
}
else
{
// City name input is invalid
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"City Name Invalid"
message:#"Unable to locate input city."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
}
}
}
}
Before:
After check button is selected:
Your issue is in these lines in cellForRowAtIndexPath:
// Assign button tags
selectButton.tag = indexPath.row;
editButton.tag = indexPath.row;
The tags will get mixed up as the cells are reused, I would recommend trying to omit using tags in this situation and use e.g. IBOutlets as #rdelmar pointed out.
I have one alert view and when I click on yes button it is supposed to produce another alert view and a toast message,but it is not happening. I couldn't figure it out. Here is my code:
-(void)myMethod {
UIAlertView *saveAlert = [[UIAlertView alloc] initWithTitle:#"First Message"
message:#"My First message"
delegate:nil
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes", nil];
saveAlert.tag=0;
[saveAlert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:NO];
}
This is the method I am using to provide the functionality for different alert views.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag==0) {
if (buttonIndex == 0)
{
//Code for Cancel button
}
if (buttonIndex == 1)
{
//code for yes button
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = #"Successfully displayed First Message";
hud.margin = 10.f;
hud.yOffset = 150.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:3];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Second Message"
message:#"My second message"
delegate:nil
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
alert.tag=1;
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:YES];
}
}
if (alertView.tag==1) {
if (buttonIndex == 0)
{
//Code for Cancel button
}
if (buttonIndex == 1)
{
//Code for yes Button
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = #"Succesfully displayed Second Message";
hud.margin = 10.f;
hud.yOffset = 150.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:3];
}
}
}
Can anyone help in finding the issue. Why I cannot get my second alert after clicking yes button in first alert?
You have not set the delegate for your UIAlertView and also make sure your delegate conforms to UIAlertViewDelegate protocol. Find the code snippet below.
You controller conforms to UIAlertViewDelegate protocol:
#interface YourViewController : UIViewController <UIAlertViewDelegate>
Create UIAlertView and set the deleagte:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"First Message"
message:#"Show second message"
delegate:self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes", nil];
[alertView show];
Implement UIAlertViewDelegate delegate method:
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if( 0 == buttonIndex ){ //cancel button
[alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
} else if ( 1 == buttonIndex ){
[alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
UIAlertView * secondAlertView = [[UIAlertView alloc] initWithTitle:#"Second Message"
message:#"Displaying second message"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[secondAlertView show];
}
}
You are specifying nil as the delegate for your alert views. You need to specify an object so the alertView:clickedButtonAtIndex: method can be called!
If you'd like to handle this more clear, you could use a block-based AlertView.
Create new file->Subclass of->UIAlertView
SuperAlertView.h
#import <UIKit/UIKit.h>
#class MySuperAlertView;
typedef void (^MySuperAlertViewBlock) (MySuperAlertView *alertView);
#interface MySuperAlertView : UIAlertView
- (instancetype) initWithTitle:(NSString *)title message:(NSString *)message;
- (void) addButtonWithTitle:(NSString *)buttonTitle block:(MySuperAlertViewBlock) block;
#end
SuperAlertView.m
#import "MySuperAlertView.h"
#interface MySuperAlertView()<UIAlertViewDelegate>
#property NSMutableArray *blocks;
#end
#implementation MySuperAlertView
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message
{
if (self = [super initWithTitle:title message:message delegate:self cancelButtonTitle:nil otherButtonTitles:nil])
{
self.blocks = [NSMutableArray array];
}
return self;
}
- (void)addButtonWithTitle:(NSString *)buttonTitle block:(MySuperAlertViewBlock)block
{
[self addButtonWithTitle:buttonTitle];
[self.blocks addObject:block ? [block copy] : [NSNull null]];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
MySuperAlertViewBlock block = self.blocks[buttonIndex];
if ((id) block != [NSNull null]){
block(self);
}
}
#end
Usage:
MySuperAlertView *alertView = [[MySuperAlertView alloc] initWithTitle:#"Info" message:NSLocalizedString(#"EMAIL_SENT_SUCCESSFULL", nil)];
[alertView addButtonWithTitle:#"Ok" block:^(MySupertAlertView *alertView) {
// handle result from ok button here
}];
[alertView addButtonWithTitle:#"cancel" block:NULL];
dispatch_async(dispatch_get_main_queue(), ^{
[alertView show];
});
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]];
}
}
}