James Patrick
James Patrick

Reputation: 263

navigational controller not passing data from tableview to viewcontroller

The code for Tableview :

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

    ViewControllerDisplayMsg *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"viewController3"];


    cellvalue=[array objectAtIndex:indexPath.row];
    detail.DisplayMsgString = cellvalue;
    [self.navigationController pushViewController:detail animated:YES];

    }

Code in viewController3 :

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.DisplayMsgLabel.text= self.DisplayMsgString;

}

The code above is not passing data its blank when the viewcontroller3 is opened.Why is the data not passing .What code is missing ?

Please help me out.Really appreciate the help.

Thanks in Advance.

Upvotes: 0

Views: 306

Answers (2)

James Patrick
James Patrick

Reputation: 263

Since I had segue from the story board The didselect method was not being called so -

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // test segue.identifier if needed
    ViewControllerDisplayMsg *viewController = segue.destinationViewController;
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    // set properties of viewController based on selection indexPath


    cellvalue=[array objectAtIndex:indexPath.row];

    NSLog(@"str :  %@",cellvalue);
    viewController.DisplayMsgtext = cellvalue;

}

This worked perfectly fine.I have to check it if this is right way of implementing but otherwise its working fine now.

Upvotes: 0

Lochana Ragupathy
Lochana Ragupathy

Reputation: 4320

You have used

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

       }

It is

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

       }

I hope you have typed it by mistake please share your result if it is something else than this

Upvotes: 3

Related Questions