1

I am newbie to iOS and learning things in iOS. I am making a demo of UITableView and Segue. I have successfully implemented table-view and now I want to pass the value to another View Controller using segue. I have tried as below, but my problem is I am getting same record every time on detail button clicked from UITableView. I don't have any idea what is wrong in my code.

Can anybody help me to figure it out?

I am posting my code here:

code

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{

    //NSDictionary *dict = [myArray objectAtIndex:indexPath.row];
  //  NSString *name = [dict valueForKey:@"name"];


    [self performSegueWithIdentifier:@"detail" sender:self];

}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"detail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        //NSLog(@"selected index path==%@",indexPath);
        DetailView *destViewController = segue.destinationViewController;
        destViewController.details = [myArray objectAtIndex:indexPath.row];
    }
}
Bista
  • 7,869
  • 3
  • 27
  • 55
net test
  • 21
  • 3

1 Answers1

2

Change your code as below, you don't need to send self as the sender. Send indexPath

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{

    [self performSegueWithIdentifier:@"detail" sender:indexPath];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"detail"]) {
        NSIndexPath *indexPath = sender;
        DetailView *destViewController = segue.destinationViewController;
        destViewController.details = [myArray objectAtIndex:indexPath.row];
    }
}
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
DilumN
  • 2,889
  • 6
  • 30
  • 44
  • Great... if this is the correct answer. Mark it as the correct answer. Then others will get help from this question as well – DilumN Dec 28 '15 at 06:34
  • 1 min to go..!can accept it as answer after 10 min only,so waiting for it – net test Dec 28 '15 at 06:36
  • hello,I have another question,can u help me bro?http://stackoverflow.com/questions/34493922/write-a-method-with-argument-in-ios – net test Dec 28 '15 at 12:57