- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@\"Action\"])
{
NSIndexPath *indexP
Like this
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)sender {
FTGDetailVC *detailVC = (id)segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
FTGNote *note = self.notes[indexPath.row];
[detailVC updateWithNote:note];
}
Swift 3.0 / iOS 10
tableView.indexPathForSelectedRow
was introduced in iOS 9
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let indexPath = tableView.indexPathForSelectedRow{
let selectedRow = indexPath.row
let detailVC = segue.destination as! ParkDetailTableVC
detailVC.park = self.parksArray[selectedRow]
}
}
sorry, i don't understand what you want to do.
it's possible get the indexPath.row
through this method of UITAbleViewDelegate
that it's called when you tap the cell of your tableView:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
self.myVariable = indexPath.row
}
and then you can access to this value in the prepareForSegue
in this way:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
//do something with self.myVariable
}
I hope i helped you.
Two cases:
Segue
connected from the viewController
Call segue
from your didSelectRowAtIndexPath
method, pass indexPath
as sender
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"Action" sender:indexPath];
}
Then you can get indexPath as sender in prepareForSegue:sender:
method
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Action"])
{
NSIndexPath *indexPath = (NSIndexPath *)sender;
SecondViewController *destViewController = segue.destinationViewController;
destViewController.getString = [getArray objectAtIndex:indexPath.row];
}
}
segue connected from the cell
No need to implement didSelectRowAtIndexPath
method and performSegueWithIdentifier:
.You can directly get sender
as UITableviewCell
in prepareForSegue:sender:
method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Action"])
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
SecondViewController *destViewController = segue.destinationViewController;
destViewController.getString = [getArray objectAtIndex:indexPath.row];
}
}