-2

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 : https://i.stack.imgur.com/3a8WQ.png

Rikesh
  • 26,156
  • 14
  • 79
  • 87
Grey_Code
  • 454
  • 1
  • 4
  • 20
  • @Larme - Thanks Larme.as i am new and don't have enough reputations i was not able to post this Ref Image. – Grey_Code Apr 22 '14 at 15:22
  • Hi. Can you please Explain whether my question is not correct or ? while downvoting ! so that i can change or know what is my mistake ! :( – Grey_Code Apr 22 '14 at 15:27
  • Your issue seems to be a problem about Object Oriented Programmation, using and reusing objects. – Larme Apr 22 '14 at 15:29
  • @Larme - Oh.ok thanks for reply Larme, but what kind of concept should i use ? any clue !! – Grey_Code Apr 22 '14 at 15:32
  • Should i create a `UIViewController` as a singleton class and use it ? if yes then while using back button in navigationbar won't the previous view's contents will be removed ? – Grey_Code Apr 22 '14 at 15:39

2 Answers2

3

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

E-Riddie
  • 14,660
  • 7
  • 52
  • 74
  • Hi Erid, now i am facing new problem like if back button is tapped then in previous view the `UITabbar` is moving up ref : http://i.stack.imgur.com/8K3nF.png – Grey_Code Apr 30 '14 at 06:41
  • any idea about this ? – Grey_Code Apr 30 '14 at 06:42
  • Erid - sorry for disturbance. i have fixed it.`self.edgesForExtendedLayout = UIRectEdgeAll;` – Grey_Code Apr 30 '14 at 06:50
  • Its ok, you can call me anytime! :) – E-Riddie Apr 30 '14 at 07:55
  • Hi Erid, I have asked a question in SO link:[http://stackoverflow.com/questions/23805863/changing-avcapturedeviceinput-leads-to-avassetwriterstatusfailed] – Grey_Code May 22 '14 at 15:34
  • Got any solution about this Issue ? for question in that link? [http://stackoverflow.com/questions/23805863/changing-avcapturedeviceinput-leads-to-avassetwriterstatusfailed] – Grey_Code May 22 '14 at 15:35
1

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.

E-Riddie
  • 14,660
  • 7
  • 52
  • 74
  • Thanks Erid, but if you are calling some friend's userID Which was tapped from ProfileViewController to display his profile. how will you load service and make same viewcontroller to PushVC ? – Grey_Code Apr 23 '14 at 09:39
  • Sorry if my question is wrong or i misunderstood !! – Grey_Code Apr 23 '14 at 09:40
  • will it be like `[self.navController pushViewController:self(or)? animated:YES];` ?? – Grey_Code Apr 23 '14 at 09:43
  • No you don't have to push it, you just need to download data, and call a method when start loading properties. But the best way is to work with 2 different ViewControllers, First one for your own profile, so you can edit properties, and the Second one for your friends profile where you can download data and present that viewController with data you have passed. – E-Riddie Apr 23 '14 at 09:46
  • ok, if user tapped another friend's profile in Second VC means then how can i load that person's Profile ? Sorry i'm little bit messedUp on this flow on calling or loading VC !! – Grey_Code Apr 23 '14 at 09:49
  • Yes, if you tap a photo of a user, first you have to check your own id with user id of that photo, if the ID are the same, you tapped your own photo and reload your profile, else if the IDs change then you have to download data with that ID, pass it to the FriendVC, and then you can push or present to that viewController. – E-Riddie Apr 23 '14 at 09:52
  • That's ok with checking my id and tapped id.my doubt is like Tapping another friend's ID from Second VC will lead to where ? calling same Second VC to reload with new values ?If yes then how it will perform Transition View animation like moving from 1 VC to Another ? Can you get my Doubt clear ?? sorry if my English is bad !! – Grey_Code Apr 23 '14 at 09:55
  • 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 ? in this place only im getting confussed !! http://storage.chrisrisner.com/images/31iosday24-view-controllers.jpg – Grey_Code Apr 23 '14 at 10:00
  • If you are in the same viewController why do you have to make a transition? The transition has to happen only if go to another profile. If you are referring from the your own ProfileVIewController, there is this way of thinking. If you think about a timeline then you have to change your way of thinking, when you tap a photo, then you have to push to yourProfileViewController or friendViewController depending on your ID. – E-Riddie Apr 23 '14 at 10:05
  • Yes. from `friendsProfileVC(VC2)`, i have selected `another person's profilePic` which is not mine.Then i have to display That `person's ProfileView` right ?Then from `friendsProfileVC(VC2)` where can i move or how can i show that person's ProfileView !! – Grey_Code Apr 23 '14 at 10:08
  • Can you get my doubt ?? – Grey_Code Apr 23 '14 at 10:15
  • You mean open friendProfile from friendProfile? Then you just have reload data on that one and show a loading view to create that ilusion! – E-Riddie Apr 23 '14 at 10:23
  • 1
    i mean i want to display n number of friends profileView on Tapping each n number of Person's Profile Pic.(like any reusable VC).just like in Facebook and Twitter.if you select your friend's Pic it'll lead to their ProfileVC and in that ProfileVC if you Tap another person's ProfilePic then it'll lead to their profileVC.But VC will be same. – Grey_Code Apr 23 '14 at 10:37
  • if you are clicking firend's profilepic from your another friend's profileVC then which VC will be made to display their selected Friend's Profile !! – Grey_Code Apr 23 '14 at 10:39
  • Can you get my Doubt ?? – Grey_Code Apr 23 '14 at 10:39
  • 1
    You mean open friendProfile from friendProfile? Yes, i think this question also fits my doubt !! i need to load Friend's Profile in FriendsProfileVC.But if personPic is selected in FriendsProfileVC means how can i load that newly Tapped friend's Data in Same VC ? – Grey_Code Apr 23 '14 at 11:09
  • Hi Erid.Can you get my doubt ?? – Grey_Code Apr 23 '14 at 11:33
  • 1
    Now I understand fully what you want. Look if you want to push the same view controller more than once, you have to create an instance of that viewController again and push that one. If you need any example code let me know, and Ill write an answer for that ok? – E-Riddie Apr 23 '14 at 12:44
  • Yes Exactly.! you are correct. this is what i was asking.Thanks for understanding.! **can you guide me by giving any sample or example code for this Process.!** Because i'm in this same process for a long time.!! – Grey_Code Apr 23 '14 at 14:07
  • Thanks a lot Erid, I will try this code and let you Know – Grey_Code Apr 24 '14 at 12:00