Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:32:16+00:00 2026-06-14T00:32:16+00:00

I’v encountered EXC_BAD_ACCESS error in my app. Or to be more specific in one

  • 0

I’v encountered EXC_BAD_ACCESS error in my app. Or to be more specific in one of my classes. It is Custom UIAlertView class. I couldn’t catch when it throws EXC_BAD_ACCESS in usage. Sometimes it works great just as expected, and in all suden it craches… Here is whole class

@implementation AlertPassword
int counter = 3;
@synthesize done;
@synthesize alertText;
@synthesize msg;
- (void) showAlert :(NSString*) title
{
    if(counter != 3){
        if(counter == 1)
        {
            NSString *msgs = @"Last warning";
            msg = msgs;
        }
        else
        {
            NSString *msgs = [NSString stringWithFormat:@"WRONG PIN. %d times remaining",counter];
            msg = msgs;

        }
    }
    else
    {
        NSString *msgs = @"Enter your pin";
        msg = msgs;
    }
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Security" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
    _alert = alert;
    _alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
    alertText = [_alert textFieldAtIndex:0];
    alertText.keyboardType = UIKeyboardTypeNumberPad;
    alertText.placeholder = @"Pin";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controlTextDidChange:)
                                                 name:UITextFieldTextDidChangeNotification object:alertText];
    [_alert show];
    [_alert release];
    [[NSNotificationCenter defaultCenter] removeObserver:UITextFieldTextDidChangeNotification];
}


- (void)controlTextDidChange:(NSNotification *)notification {
    {
        NSString *pin = [[NSUserDefaults standardUserDefaults] stringForKey:@"Pin"];
        if ([notification object] == alertText)
        {
            if (alertText.text.length == pin.length)
            {
                if(counter != 0)
                {

                    if([alertText.text isEqualToString:pin])
                    {
                            [_alert dismissWithClickedButtonIndex:0 animated:NO];
                            [self.tableViewController openSettings];
                            counter = 3;
                    }
                    else
                    {
                            counter--;
                            [_alert dismissWithClickedButtonIndex:0 animated:NO];
                            [self showAlert:@""];

                    }
                }
                else
                {
                    [_alert dismissWithClickedButtonIndex:0 animated:NO];
                    [[NSUserDefaults standardUserDefaults] setObject:NULL
                                                              forKey:@"Telephone"];
                    [[NSUserDefaults standardUserDefaults] setObject:NULL
                                                              forKey:@"Pin"];
                    [[NSUserDefaults standardUserDefaults] synchronize];
                    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"" message:AMLocalizedString(@"EraseData", nil) delegate:nil cancelButtonTitle:AMLocalizedString(@"Ok", nil) otherButtonTitles:nil];
                    counter = 3;
                    [av show];
                    [av release];
                }

            }
        }
    }

}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *pincheck = [[NSUserDefaults standardUserDefaults] stringForKey:@"pinCheck"];
    if (buttonIndex == 0)
    {
        if(pincheck.intValue == 1)
        {
           NSLog(@"app kill");
            exit(0);
        }
        else
        {
            NSLog(@"dismiss");
        }
    }

}
@end

Here is where i initialize and use this class.

            case 5:
            NSLog(@"Add remove");
            if (pincheck != NULL && pin != NULL){
                if([pincheck isEqualToString:@"0"])
                {

                    AlertPassword *alert = [AlertPassword alloc];
                    alert.tableViewController = self;
                    NSString *msg = @"Enter your pin code to access:";
                    [alert showAlert:msg];
                //    [alert release];

                }
                break;
            }
            else
            {
                NSLog(@"Is null");
                [Menu load2View:self];
            }
            break;

I though maybe it was because i do not release alert. But adding [alert release]; Made to have EXC_BAD_ACCESS directly after the user tries to enter something. Without [alert release]; it works. But sometimes it craches with EXC_BAD_ACCESS

Also sometimes it gets

2012-11-08 12:11:27.451 kodinisRaktas[2485:19d03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ dismissWithClickedButtonIndex:animated:]: unrecognized selector sent to instance 0x947aae0'

But I also have no idea why this happends

Please help, I’m pretty new to objective-c and ios, and I have no idea how to get rid of this, I guess someone with a bit of experience will see whats wrong in my code.

I’v just saw, that EXC_BAD_ACCESS or unrecognized selector throws if you push cancel for 4-5 times or more, and then try to type something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:32:18+00:00Added an answer on June 14, 2026 at 12:32 am

    EXC_BAD_ACCESS is mostly due to bad memory handling. The alert has most likely become an zombie… I would have the alert as a property with strong/retain. You should hold on to it while displaying. Not release after “show”.

    When you set up the first you can do like this

    _alert = [[UIAlertView alloc] initWithTitle:@"Security" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil]; // retain count: 1
    

    Note calling “show” will also retain it, but that does not change the fact that you need to too.

    [_alert show]; // retain count: 2
    

    Wait for the delegate callback and release it.

    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
        [_alert release], _alert = nil; // retain count in next run will be 0
    }
    

    Tip: It may be easier to handle if you use UIAlertView combined with blocks. http://gkoreman.com/blog/2011/02/15/uialertview-with-blocks/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.