Suppose we have 2 viewControllers, the first one is class FriendViewController
and other is class UserViewController
.
Step 1
We are at UserViewController
. When you tap an image of a
specified user you check your id with the id that the user has.
Step 2
Depending on user id, if the user id is the same as yours, you tapped your image, so you don't have to go to another viewController, so just reload your data for any update.
Step 3
Else is user id is different, we are dealing with another user, so we have to go to another FriendViewController. Example doing that:
FriendViewController *fc = [[FriendViewController alloc]init];
[self.storyboard instantiateViewControllerWithIdentifier:@"friendvcID"];
fc.stuff = stuff;
[self.navigationController pushViewController:fc animated:YES];
Step 4
Now we are at FriendViewController and if depending on a image we tap, if we have it as the same as our id, we are navigating to our profile, so what we do is check if we already have it to our navigationStack, if we don't we need to push.
//Check if we have userProfile on navigationStack
if ([self hasUserProfileOnStack]!=-1)
{
//We have it on specific index, so we are popping to that viewController, which is UserViewController
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:[self hasUserProfileOnStack]] animated:YES];
}
else
{
//We dont have it in navigationStack so we are pushing it
UserViewController *fc = [[UserViewController alloc]init];
[self.storyboard instantiateViewControllerWithIdentifier:@"uservcID"];
fc.stuff = stuff;
[self.navigationController pushViewController:fc animated:YES];
}
//Method which helps us to find if we have it to navigationStack by returning the index on navigationControllers
-(NSInteger)hasUserProfileOnStack
{
for (NSInteger i=0; i<[self.navigationController.viewControllers count]; i++)
{
if ([[self.navigationController.viewControllers objectAtIndex:i] isKindOfClass:[UserViewController class]]) {
return i;
}
}
return -1;
}
Step 5
If that ID is not as the same as our ID then we just have to execute Step 3
This is the info that I could give to you right now, it's a bit difficult explaining with words, but this is how I can explain it here. Hope it helps