Search code examples
iosobjective-cuiactionsheet

How to perform reset of textfield using actionsheet?


I want to reset the textfields of myview to empty when an actionsheet destructive button is pressed. Done button calls the actionsheet. This is my actionsheet:

- (IBAction)submit:(id)sender {
    UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:@"Options" delegate:sender cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Reset" otherButtonTitles:@"Save", nil];
    [sheet showInView:self.view];
}

And is used this method to reset:

- (void)sheet:(UIActionSheet *)sheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==0)
    {
        self.textf1.text = @"";
    }
}

But Nothing is happening.

enter image description here

enter image description here


Solution

  • Replace delegate:sender to delegate:self that's why delegates

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    

    are not getting call also update the delegate function, once you done just set all textFiled to .text= @"". i hope it will work

    Also posted as Comment earlier.