Reputation: 1261
I'm tying to call didDismissWithButtonIndex
on UITextView
Class ,but it not called.
I also implement UIAlertViewDelegate
on MyViewcontroller.h
file and [alert setDelegate:self]
to method.
So is that possible to call UIAlertView
Delegate method in UITextView
Class ??
+ (void)deleteTextr:(UITapGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"Delete Text !!!!" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"No", nil];
[alert setDelegate:self];
[alert show];
}
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1)
{
[self removeFromSuperview];
}
}
Upvotes: 0
Views: 1112
Reputation: 18181
deleteTextr:
is a class method. In the context of a class method, self
is just a reference to the class. To use the UIAlertViewDelegate protocol, you need assign an instance of a class to the UIAlertView instance's delegate property, which can only be done within an instance method.
Read this to get a better grasp of the aforementioned concept.
Upvotes: 2
Reputation: 2768
just change delegate method to class method. like this:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
// - change to +
+ (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
Upvotes: 2