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 1014031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:36+00:00 2026-05-16T10:11:36+00:00

In the below code not invoked the willPresentAlertView method. Why? The method is static?

  • 0

In the below code not invoked the willPresentAlertView method.
Why? The method is static? or The Alert value is static?

@interface ShowAlert : NSObject <UIAlertViewDelegate>

static UIAlertView* alert;

    +(void) showAlert:(NSString*) msg{      
        alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"%@", msg] delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
        [alert show];
    }

    - (void)willPresentAlertView:(UIAlertView *)alertView {
        NSLOG(@"willPresentAlertView");
    }
  • 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-05-16T10:11:37+00:00Added an answer on May 16, 2026 at 10:11 am

    There’s no such thing as a static method in Objective-C, and the storage classes of your variables have nothing to do with what UIKit does.

    Here’s what you did:

    1. You implemented a class method and created the alert in it.
    2. In this method, you set the alert’s delegate as self; since this is in a class method, self is the class, which means you set the alert’s delegate to the ShowAlert class.
    3. You showed the alert. Since the alert’s delegate—the ShowAlert class—does not respond to willPresentAlertView:, the alert does not attempt to send that message.

    “What!”, you say. “I implemented willPresentAlertView:!”

    Well, yes, you implemented it as an instance method. Thus, instances of ShowAlert respond to that message. But the alert’s delegate is not an instance of ShowAlert; it is the ShowAlert class itself, which does not respond to that message, because you implemented it as an instance method and not a class method.

    I don’t understand why you’ve made a class for this in the first place. Shouldn’t whatever wants to show the alert create, be the delegate of, and show the alert itself? Why put another class in between? (Note that classes should generally be named for nouns, not verbs; the name of this class being “ShowAlert” is what tips me off that you’re doing something wrong here.)

    If you insist on having this class, you should either make each instance create, be the delegate of, and show a UIAlertView (and, accordingly, make alert an instance variable rather than a static variable in the implementation file), or make the class respond to willPresentAlertView: by changing your implementation of it from an instance method to a class method.

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

Sidebar

Related Questions

I've been read this article : commandButton/commandLink/ajax action/listener method not invoked or input value
Below code not work, but it's work fine for jsf1.2. Now the framework is
The code below does not work but meant to illustrate what I want to
When i tried using the below code...the td tag is returned and not the
I am getting an compilation error not a statement for the below code. Not
I am using the below code, but I am not getting that why it
I am using the below code to initialise a jQuery FullCalendar. However, not all
I am having a problem with the below code. I am not sure why
The code below produces an error saying that my input string was not in
W.r.t code below I can not declare the type of fetch-into-variable as the underlying

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.