Question

I trying to pass the data from TableViewCell to the another ViewController.But No data Displaying in the another ViewController.here is my Code

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


   PeripheralManager *objSelected=[device objectAtIndex:indexPath.row];

   [self prepareForSegue:@"TableDetails" sender:objSelectedDevice];
 }


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


   if ([segue.identifier isEqualToString:@"TableDetails"])
   {


   DetailViewController *detail=segue.destinationViewController;
   detail.dataArray=device;
   }

 }

Error Message

nested push animation can result in corrupted navigation bar
2012-10-24 12:01:39.805 [3182:707] nested push animation can result in corrupted navigation bar
2012-10-24 12:01:40.164 [3182:707] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2012-10-24 12:01:40.167 [3182:707] Finishing up a get navigation transition in an unexpected state. Navigation Bar subview tree might corrupted.
Was it helpful?

Solution

Remove your extra code Only do this-

In DetailViewController.h

@property(nonatomic, retain)NSMutableArray *dataArray;

In DetailViewController.m

@synthesize dataArray = _dataArray;

Now In TableViewController.m Just write this -

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if([segue.identifier isEqualToString:@"TableDetails"])
   {
     DetailViewController *detailViewObject = segue.destinationViewController;
     detailViewObject.dataArray = anyArray;
   }
}

Here I'm passing NSMutableArray.

OTHER TIPS

You do not need this:

[self.navigationController pushViewController:mdc animated:YES];

That is what Segue will do automatically

Also, you are having 3 lines that will load view controller - see below for comments:

NSInteger row=[indexPath row];
NSString *value=[device objectAtIndex:row];
MeBleDetailViewController *mdc=[self.storyboard instantiateViewControllerWithIdentifier:@"MeBleDetailViewController"];  
mdc.deviceName=value;
[self presentModalViewController:mdc animated:YES];    // Load ViewController
[UIView commitAnimations];
[self performSegueWithIdentifier:@"TableDetails" sender:[device objectAtIndex:indexPath.row]];    // Load ViewController
[self.navigationController pushViewController:mdc animated:YES];   // Load ViewController

That is why you are getting that error: nested push animation can result in corrupted navigation bar

Also, If you have configured the segue from table cell to another view controller then you don't need anything in didSelectRowAtIndexPath method.


Edit:

Whatever data you want the pushed view controller to have - put it in prepareforSegue method instead of didSelectRowAtIndexPath

If you create a segue from table cell to view controller then you don't need to execute the following as this method is to execute the segue programmatically.

[self performSegueWithIdentifier:@"TableDetails" sender:[device objectAtIndex:indexPath.row]];

OK. Let's say you have two viewcontrollers FirstViewController and SecondViewController. In FirstViewController you have a tableview and of course tableviewcell. In SecondViewControlleryou need to display data. So in SecondViewController.h you need to set a propery of some variable, in this case it is of id type @property (strong, nonatomic) id secDetailItem;. Synthesize it in SecondViewController.m and add a setter method like this

-(void)setDetdetailItem:(id)newSecdetailItem{
if (secDetailItem != newSecdetailItem) {
    secDetailItem = newSecdetailItem;

    // Update the view.
     [self configureView];//This method is needed to update view if there are some changes in that view.
}
}

So then in FirstViewController.h import SecondViewController.h and add property @property (strong, nonatomic) SecondViewController *secondViewController; then synthesize. In FirstViewController.m file in this delegate method do following:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
 self.secondViewController.secDetailItem=//set your data should be passed.

//Also if you need to push viewcontroller add pushviewcontroller:SecondViewController, or use IB to connect tableview cell and SecondViewController together with push method. }

In this case you will not need to use perform segue. The Setter method will work as soon as you set to the secDetailItem something.

Also if you need to update your view in SecondViewController add this method to it.

- (void)configureView

{

if (self.secDetailItem) {
    self.textLabel.text=self.secDetailItem;//Data passed from FirstViewController
}

}

This is all you need to do. Sorry if it is complicated. Ask any question.

It might have something to do with this line:

[UIView commitAnimations];

You can delete it if you don't need it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top