The solution i've found:
Preparations:
Make your controller conform to protocol
UIAlertViewDelegate
.
Example:
@interface YourViewController : UITableViewController
to
@interface YourViewController : UITableViewController <UIAlertViewDelegate>
.In storyboard, set the segue identifier. Let me call it CellSegue for this example.
(To to so, click the segue in the storyboard, go to Attributes Inspector and there is Identifier field)You will need 2 properties.
@property (strong, nonatomic) UITableView *selectedCellTableView;
@property (strong, nonatomic) NSIndexPath *selectedCellIndexPath;
Coding:
The method below, displays alertview
and prevents the cell from being selected by returning nil
. We want to remember which cell was to become selected, so we set properties prepared before as follows:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:nil message:@"alert" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
_selectedCellTableView = tableView;
_selectedCellIndexPath = indexPath;
[av show];
return nil;
}
Lastly, in UIAlertViewDelegate
method we handle a button click:
- We get the cell at
_selectedCellIndexPath
from_selectedCellTableView
, - We perform the CellSegue segue and set the cell as a sender.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
//1
UITableViewCell *cell =[_selectedCellTableView cellForRowAtIndexPath:_selectedCellIndexPath];
//2
[self performSegueWithIdentifier:@"CellSegue" sender:cell];
}
I hope it was what you were looking for :)