-3
-(void)otherGames
{
    UIAlertView *alertMsg = [[UIAlertView alloc]
    initWithTitle:@"This gGame was Developed By:"
    message:@"Burhan uddin Raizada"
    delegate:nil
    cancelButtonTitle:@"Dismiss"
    otherButtonTitles: @"@twitter" , nil];
    [alertMsg show];

}

-(void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn… {

    if (buttonIndex == 1) {
        NSString *containingURL = [[NSString alloc] initWithFormat:@"http://www.twitter.com/…
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: containingURL]];
    }
}

the first alertmsg is working absolutely fine. but when i added a like to the new "@twitter" button, then it just doesn't work. otherwise everything is working fine. i am wondering why it doesn't, but it should..need help.

Edelweiss
  • 621
  • 1
  • 9
  • 24
  • 1
    No need to label your question as urgent. Every question will get the attention it deserves in a community as large as this one. – Cezar Aug 07 '12 at 13:55
  • **FIRST:** you haven't delegated your class, `delegate:nil` shows there is no delegated class for the `UIAlertView`. **SECOND:** the correct name of the callback method is: `-alertView:didDismissWithButtonIndex:`... now, you know why this code fragment is totally **wrong**. any other question? :) – holex Aug 07 '12 at 14:03
  • @holex, why dont you provide an answer? – vikingosegundo Aug 07 '12 at 17:28
  • @vikingosegundo, my answer was provided above, it should be enough for him to make the right code, I guess. – holex Aug 07 '12 at 22:15
  • @holex But than this answer cant be accept, and therefore this thread will appear as not answered. and that will lead to confusion for other people and the system will randomly touch it to raise attention. As questions shouldn't go to answers, comments should contain comments, and not answers. those belong — i guess you know where this leads — into answers. – vikingosegundo Aug 07 '12 at 22:53
  • @vikingosegundo you are probably right but my experience says there no guarantee of the newbie asker will accept any answer, so, I'll do it a little later. – holex Aug 08 '12 at 07:21

2 Answers2

-1

Assuming that

- (void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn…

is

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

You must set your delegate to self and add the delegat protocol to your header :

@interface yourView : UIViewController <UIAlertViewDelegate>

Edit : According to @holex, use alertView:willDismissWithButtonIndex: instead of -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

Edelweiss
  • 621
  • 1
  • 9
  • 24
  • it is still **wrong**. the name of the callback method is definitely not that. – holex Aug 08 '12 at 08:05
  • You're right, this is why I assumed that he wrote wrongly the method. But if the method was written correctly it probably wont work because he did not set the delegates to `self` – Edelweiss Aug 08 '12 at 09:52
  • **-1. twice!** how can you say to this _wrong_ method `-alertView:clickedButtonAtIndex:` is **same** as the _good_ method `-alertView:didDismissWithButtonIndex:`...? have you ever read the `UIAlertViewDelegate` protocol reference? – holex Aug 08 '12 at 09:55
  • Before put me -1 try the read what I wrote : **I assumed that he wrote wrongly the method.**, not he used the wrong method. – Edelweiss Aug 08 '12 at 09:58
  • **-1. third time, because your method is still wrong** and it seems you don't take care of it. when do you want to correct **your wrong method** in your answer? :( – holex Aug 08 '12 at 10:09
  • I know what you mean, but I am wondering what is the difference between `alertView:clickedButtonAtIndex:` and -`alertView:didDismissWithButtonIndex:` (will edit if your answer convince me, I'm just curious and I never used this method ;)) – Edelweiss Aug 08 '12 at 11:06
  • the difference is very easy. this method `-alertView:clickedButtonAtIndex:` is called **before** the `UIAlertView` is dismissed and it calls the dismiss process automatically (now!), the other method `-alertView:didDismissWithButtonIndex:` will be called **after** the `UIAlertView` dismissed already. what if the Apple changes the calling process of the `-alertView:clickedButtonAtIndex:` method on one day and it won't call the dismiss method automatically? will you rewrite all of your projects to dismiss manually the `UIAlertView`? how could you do it...? where have you learnt this technique? – holex Aug 08 '12 at 11:38
-2

UPDATE

this answer has been outdated since UIAlertView is deprecated in iOS8.

you can read more about UIAlertController on Apple's Dev Docs.


FIRST:

you haven't delegated your class, delegate:nil shows there is no delegated class for the UIAlertView. your should correct your method following this:

-(void)otherGames
{
    UIAlertView *alertMsg = [[UIAlertView alloc]
    initWithTitle:@"This gGame was Developed By:"
    message:@"Burhan uddin Raizada"
    // delegate:nil
    delegate:self // don't forget to implement the UIAlertViewDelegate protocol in your class header
    cancelButtonTitle:@"Dismiss"
    otherButtonTitles: @"@twitter" , nil];
    [alertMsg show];

}

SECOND:

the correct name of the callback method is: -alertView:didDismissWithButtonIndex:

//-(void)alertMsg:(UIAlertView *)alertMsg clickedButtonAtIndex:(NSInteger)buttonIn… { // WRONG, where have you got this silly idea...?
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        NSString *containingURL = [[NSString alloc] initWithFormat:@"http://www.twitter.com/…
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: containingURL]];
    }
}

now, you know why your code fragment is wrong.

holex
  • 23,961
  • 7
  • 62
  • 76