I am trying to use the SCLAlertView library to display an alert view when you click on a button in a table view cell. I'm presenting it like this from my tableviewcell.m:
- (IBAction)showSuccess:(id)sender {
SCLAlertView *alert = [[SCLAlertView alloc] init];
[alert addButton:@"First Button" target:self selector:@selector(firstButton)];
[alert addButton:@"Second Button" actionBlock:^(void) {
NSLog(@"Second button tapped");
}];
[alert showSuccess:self title:@"test" subTitle:@"test" closeButtonTitle:@"test" duration:0.0f];
}
But when I click on the button the app crashes and gives me this error:
[TableViewCell addChildViewController:]: unrecognized selector sent to instance 0x126e1bc90
It also gives me this warning on the line where I actually show the alert:
Incompatible pointer types sending 'TableViewCell *' to parameter of type 'UIViewController *'
I'm guessing I can't display a View Controller from my Table View Cell, but how could I solve this?
You have to add the parent view controller of the cell as childViewController.
So add a delegate in the cell, attach it in the TableViewController and then call the alert from the TableViewController when triggered from the cell delegate.