2

I am trying to call UIAlertView's delegate method programmatically. Here is the code:

if([vc respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
        // Manually invoke the alert view button handler
        [(id <UIAlertViewDelegate>)vc alertView:nil
                           clickedButtonAtIndex:0];
    }

It works fine on iOS5.0 but is not working on iOS6.0 and comments or suggestions are most welcomed :)

Here is the complete method for detail:

TWTweetComposeViewController *vc = [[[TWTweetComposeViewController alloc] init]autorelease];
    // Settin The Initial Text
    [vc setInitialText:status];
    [vc setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
        if(result == TWTweetComposeViewControllerResultDone) {

            NSLog(@"Tweeted Sucessfully");
            }
    }];
    if([delegate isKindOfClass:[UIViewController class]]){
        [(UIViewController *)delegate presentModalViewController:vc animated:YES];
    }
      //alertView:clickedButtonAtIndex:
    if([vc respondsToSelector:@selector(alertView:clickedButtonAtIndex:)]) {
        // Manually invoke the alert view button handler
        [(id <UIAlertViewDelegate>)vc alertView:nil
                           clickedButtonAtIndex:0];
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Zubair
  • 5,833
  • 3
  • 27
  • 49

5 Answers5

2

in you code just give the alertview with your alertview obect name like bellow..

[(id <UIAlertViewDelegate>)vc alertView:yourAlertView
                           clickedButtonAtIndex:0];

otherwise Just try with this bellow code..

   id<UIAlertViewDelegate> delegate = yourAlertView.delegate;
    yourAlertView.delegate = nil;
    [delegate alertView:yourAlertView clickedButtonAtIndex:0];

see this link for some other option about it..

why-doesnt-dismisswithclickedbuttonindex-ever-call-clickedbuttonatindex

Community
  • 1
  • 1
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • Actully I am trying to tap the "Settings" button on TWTComposeViewController's alertView.. i do not know whats the name of its alertview – Zubair Feb 19 '13 at 06:02
  • hey see this link may you get some idea from this http://stackoverflow.com/questions/12626821/app-would-like-access-to-twitter-accounts-alert-is-not-shown-in-ios-6 i hope its help you.. – Paras Joshi Feb 19 '13 at 06:09
2

It is bad practice to directly call delegate methods. UIAlertView has a method called dismissWithClickedButtonIndex:animated:. If you call that, the UIAlertViewDelegate methods alertView:willDismissWithButtonIndex: and alertView:didDismissWithButtonIndex: will be called, assuming your delegate is set correctly.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
1

You can use this delegate this will work for you..

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  
SachinVsSachin
  • 6,401
  • 3
  • 33
  • 39
1

There are no such differences regarding implementation of Alert view in iOS 6. You can complete your task easily by using this delegate method - :

(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  

try this and after that let us know what kind of warning you get in console...

Vineet Singh
  • 4,009
  • 1
  • 28
  • 39
  • I am using this to dismiss the TWTComposeViewController's AlertView and its not being dismissed, Tried the alertView: didDismissWithButtonIndex. – Zubair Feb 19 '13 at 06:11
0

TWTeetComposeViewController deprecated in IOS6. Please try with DETweet instead. :) Works fine on iOS 6 too. :)