1

According to my project design, the navigation stack structured like below: Splash Screen -> Home -> Event Listing -> Event Details

Now, i use Custom Url which the Url calls 'Home' page. So, I want to change the Navigation Stack structure like below: Splash Screen -> Home

Through my knowledge, my code facing some memory problem:

  • I can code that only reach the stack like: Splash -> Home -> Home -> Home -> …. and so on, whenever i use custom url.

  • Otherwise, using popToviewController I can reach the stack like: Splash -> Home -> Home

But, the push successfully happened but the view not change.

Code below:

navigationArray = [[NSMutableArray alloc] initWithArray: self.nav.viewControllers];
for(int k=[navigationArray count]-1;k>=0;k--){
    if ([[navigationArray objectAtIndex:k] isKindOfClass:[Home class]]){
        //UIViewController *controller=[navigationArray objectAtIndex:k];
        id obj=[navigationArray objectAtIndex:k];
        [[self nav] popToViewController:obj animated:YES];
    }
}

if(IS_IPAD)
    class=[[Home alloc] initWithNibName:@"Home_iPad" bundle:Nil];
else
    class=[[Home alloc] initWithNibName:@"Home" bundle:[NSBundle mainBundle]];

 [self.nav pushViewController:class animated:YES];    
NSLog(@"Finally, In Nav: %@", [self.nav viewControllers]);

This prints like below:

"Splash: 0xcea0c70",
"Home: 0xd193400",
"Home: 0xd470600".

That is, Splash -> Home -> Home. But, Simulator displays the Home: 0xd193400 not the Home: 0xd470600. Why?

  • Your question is not clear. I think its better if you can rephrase your problem. – Naga Mallesh Maddali Jul 15 '14 at 11:40
  • add your code where you are pushing Edit Listing View Controller – Naga Mallesh Maddali Jul 15 '14 at 11:43
  • Please see the code which i posted, and answer me the question whatever you know. – user3483975 Jul 15 '14 at 11:52
  • @Naga OP asked one question at end of the post clearly. Push happened but that pushed view not displayed. ie. Displaying the "Home: 0xd193400" not the "Home: 0xd470600". i dont know why it happened. – Mohd Sadham Jul 15 '14 at 11:57
  • @UdanPirappu, thats why I have asked him to provide more information. He is just asking to give answer by seeing the code which he has posted. If you understood what is problem, you can explain me. Also please explain what does this means "Displaying the "Home: 0xd193400" not the "Home: 0xd470600" – Naga Mallesh Maddali Jul 15 '14 at 12:03
  • @Naga Ok, Now we focus only that code and him question. Don't see him project logic. According to that code, the navigation pop upto the home class. And then push newly allocated Home class successfully. And he also print the Navigation array(you can see and compare with him question). But, last he mentioned that the Simulator does not change to view newly pushed class. Thats why he said like displays only **Home Page of memory: 0xd193400** not the **Home Page of memory: 0xd470600** – Mohd Sadham Jul 15 '14 at 12:14

2 Answers2

1

Same problem facing here...But i don't why this is happing.. So i've done this trick and you can also apply

navigationArray = [[NSMutableArray alloc] initWithArray: self.nav.viewControllers];
for(int k=[navigationArray count]-1;k>=0;k--){
    if ([[navigationArray objectAtIndex:k] isKindOfClass:[Home class]]){
        //UIViewController *controller=[navigationArray objectAtIndex:k];
        id obj=[navigationArray objectAtIndex:k];
        [[self nav] popToViewController:obj animated:YES];
    }
}

[self performSelector:@selector(pushViewController) withObject:nil afterDelay:.60];

- (void)pushViewController
{
   if(IS_IPAD)
     class=[[Home alloc] initWithNibName:@"Home_iPad" bundle:Nil];
   else
     class=[[Home alloc] initWithNibName:@"Home" bundle:[NSBundle mainBundle]];

   [self.nav pushViewController:class animated:YES];    
   NSLog(@"Finally, In Nav: %@", [self.nav viewControllers]);
}

2. Solution

if you are running this method in background thread

then use this one

[self performSelectorOnMainThread:@selector(pushViewController) withObject:nil waitUntilDone:NO];
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
1

These are all under the concept of Threading. Due to some block of thread under the semaphore concept, the pop completed but the push not happened even it were allocated. So, the answer of @Dharmbir is completely useful for avoiding the navigation problem under what asked by OP. There will be many other problems will face by the OP after followed the @Dharmbir ideas.

For Example,

  • reason: 'Can't add self as subview'

  • Unbalanced calls to begin/end appearance transitions for "Home: 0xe671800"

For such be avoid above error, we must follow below advices which were given by other Stack Overflow users.

Can't add self as subview

iOS app error - Can't add self as subview

"Unbalanced calls to begin/end appearance transitions for DetailViewController" when pushing more than one detail view controller

Community
  • 1
  • 1
Mohd Sadham
  • 435
  • 3
  • 19