Reputation: 6203
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];
}
}
Upvotes: 2
Views: 1080
Reputation: 454
TWTeetComposeViewController deprecated in IOS6. Please try with DETweet instead. :) Works fine on iOS 6 too. :)
Upvotes: 0
Reputation: 4019
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...
Upvotes: 1
Reputation: 16946
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.
Upvotes: 2
Reputation: 20541
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
Upvotes: 2
Reputation: 6427
You can use this delegate this will work for you..
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
Upvotes: 1