Question

If we Tap any Profile Picture it will lead to their Profile View. Even in same view if user taps Other's Profile Pic like in Followers list, then it should lead to their profile View.But the View controller is same.Just Same functionalities as Facebook and Twitter. I need to implement this Functionality. But I don't know how can I achieve this process. Using same profile UIViewController for multiple Users.

Or is there any other way to achieve this Functionality ? Please guide me how can I achieve this Process.

For Example : VC1 is myprofileVC and VC2 is friendsProfileVC. i'm selecting friend's Pic in myprofileVC(VC1) and loadingData in friendsProfileVC(VC2).then if i select another person's ProfilePic in friendsProfileVC(VC2) means where it should lead ? or what to do ? How to Loaded that Newly Selected Person's ProfileView?In Same (VC2) or ? in this place only im getting confused !!

Ref Image : http://i.stack.imgur.com/3a8WQ.png

Was it helpful?

Solution

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

OTHER TIPS

You should start learning iOS Programming from scratch, and start developing apps step by step. There are plenty of sites and books where you can learn. I would suggest Ray Wenderlich because it has great iOS tutorials.

Referring to that question you have, I am developing a social iOS app right now where this thing is achieved by:

  1. Using an ID for every User
  2. I download data on a specific server by sending that ID
  3. Passing them to the ProfileViewController properties which are declared in .h file
  4. Then I load these properties there where I want

Anyway I think is too early for you to achieve these things, you have to learn iOS step by step and practice will give you experience to achieve great things.

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