Search code examples
iosxcodeuiactionsheetuiactionsheetdelegate

UICustomActionSheet not calling delegate method to handle events


i am using this example in my code. And it is working just fine for now but when i tap on a button it did not respond or call any method. here is my code:

UICustomActionSheet* customActionSheet = [[UICustomActionSheet alloc] initWithTitle:nil delegate:nil buttonTitles:@[@"Cancel",@"Delete picture", @"Take a new photo", @"Choose from existing"]];
    [customActionSheet setButtonColors:@[[UIColor redColor]]];
    [customActionSheet setBackgroundColor:[UIColor clearColor]];
    [customActionSheet setSubtitle:@"Select your Choice"];
    [customActionSheet setSubtitleColor:[UIColor whiteColor]];
    [customActionSheet showInView:self.view];

and here is method that needs to be called

-(void)customActionSheet:(UICustomActionSheet *)customActionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"%d",buttonIndex);
}

Solution

  • The problem is with your delegate. You have set it nil. Set it to self and your problem will be solved.