Melexia
Melexia

Reputation: 3

Separate two controllers that show in iPad in the same screen for use in iPhone

I am trying to convert an iPad project to an iPhone project. I used to work with Android apps so it's being a hard work for me.

In iPad I have a screen with two containers: ContainerProfile and ContainerSection. The container profile always show the profile and the containersection is for showing the different options that you can choose in a menu, and things like ranking, social, rewards...

In iPhone these containers never will see it at the same time, because have a smaller screen, so what I can do to separate it? tell me if you need more information.

Sorry because i didn't explain it good. The menu is in the top bar and you see the information about this menu in the right container, but now in iPhone this is not possible. I give the code for you have more idea.

#import “ATMyProfileContainerViewController.h"
#import “ATMyProfileMainViewController.h"
#import “ATSocialSectionContainerViewController.h"
#import “ATPortfolioSectionContainerViewController.h"
#import “ATUserRankingSectionContainerViewController.h"
#import “ATPortfolioRankingSectionContainerViewController.h"
#import “ATAchievementSectionContainerViewController.h"
#import “ATConnectionHelper.h"
#import “ATConstants.h"
#import "HelperText.h"
#import “ATAppDelegate.h"
#import “ATPicture.h"
#import "Pictures.h"
#import "Pictures+Create.h"
#import “ATSectionContainerViewController.h"

@interface ATMyProfileContainerViewController()<ATConnectionHelperDelegate>{
   ATSectionContainerViewController *_currentSectionController;
    ATMyProfileOptions _currentOptionSelected;

}
@property (nonatomic,weak) ATMyProfileMainViewController *myProfileViewController;

@property (weak, nonatomic) IBOutlet UIView *viewContainerProfile;
@property (weak, nonatomic) IBOutlet UIView *viewContainerSection;

@end

@implementation ATMyProfileContainerViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)loadUserProfile:(ATPrivateUserProfileModel *)profile{
    self.userProfile=profile;
    TAMyProfileMainViewController* controller;
    if (_myProfileViewController==nil) {
        controller= [self.storyboard instantiateViewControllerWithIdentifier:@“ATMyProfileMainViewController"];

    }else
    {
        //controller=_myProfileViewController;
    }
    [controller setUserProfile:self.userProfile];
    [self setProfileInContainer:controller];
    // [_myProfileViewController reloadData];

}

- (void)setProfileInContainer:(ATMyProfileMainViewController*)controller{
    if (_myProfileViewController) {
        [_myProfileViewController.view removeFromSuperview];
        [_myProfileViewController removeFromParentViewController];
        _myProfileViewController=nil;
    }
    if (controller!=nil) {
        controller.view.frame=self.viewContainerProfile.bounds;
        [self addChildViewController:controller];
        [self.viewContainerProfile addSubview:controller.view];
        [controller didMoveToParentViewController:self];
        _myProfileViewController=controller;
    }
}

-(void)selectSection:(ATMyProfileOptions)optionSelected{
    _currentOptionSelected=optionSelected;

    if (optionSelected==Social) {
        ATSocialSectionContainerViewController *socialController=[self.storyboard instantiateViewControllerWithIdentifier:@"SocialSectionContainer"];
        socialController.userProfile=self.userProfile;
        [self replaceSectionControllerWith:socialController];
    }
    else if (optionSelected==Profiles){
        ATMyProfileMainViewController *Controller=[self.storyboard instantiateViewControllerWithIdentifier:@“ATMyProfileMainViewController"];
        Controller.userProfile=self.userProfile;
        [self replaceSectionControllerWith:Controller];

    }
    else if (optionSelected==Portfolios){
        ATPortfolioSectionContainerViewController *portfolioController=[self.storyboard instantiateViewControllerWithIdentifier:@"PortfolioSectionContainer"];
        portfolioController.userProfile=self.userProfile;
        portfolioController.portfolioInfoDelegate=self.portfolioInfoDelegate;
        [self replaceSectionControllerWith:portfolioController];

    }
    else if (optionSelected==UserRanking){
        ATUserRankingSectionContainerViewController *userRankingController=[self.storyboard instantiateViewControllerWithIdentifier:@"UserRankingSectionContainer"];
        userRankingController.userProfile=self.userProfile;
        [self replaceSectionControllerWith:userRankingController];

    }
    else if (optionSelected==PortfolioRanking){
        ATPortfolioRankingSectionContainerViewController *portfolioRankingController=[self.storyboard instantiateViewControllerWithIdentifier:@"PortfolioRankingSectionContainer"];
        portfolioRankingController.userProfile=self.userProfile;
        portfolioRankingController.portfolioInfoDelegate=self.portfolioInfoDelegate;
        [self replaceSectionControllerWith:portfolioRankingController];

    }
    else if (optionSelected==Achivements){
        ATAchievementSectionContainerViewController *achievementController=[self.storyboard instantiateViewControllerWithIdentifier:@"AchievementSectionContainer"];
        achievementController.userProfile=self.userProfile;
        [self replaceSectionControllerWith:achievementController];

    }
}

-(void) replaceSectionControllerWith:(ATSectionContainerViewController *)newController{

    [UIView transitionWithView:self.viewContainerSection
                      duration:0.5
                       options:UIViewAnimationOptionTransitionFlipFromBottom
                    animations:^(void){
                        if (_currentSectionController){
                            [_currentSectionController.view removeFromSuperview];
                            [_currentSectionController removeFromParentViewController];
                            _currentSectionController=nil;
                        }

                        if(newController)
                        {
                            newController.goPublicProfileDelegate=self.goPublicProfileDelegate;
                            newController.view.frame=self.viewContainerSection.bounds;
                            [self addChildViewController:newController];
                            [self.viewContainerSection addSubview:newController.view];
                            [newController didMoveToParentViewController:self];
                            _currentSectionController=newController;
                        }
                    }
                    completion:NULL];

}

#pragma mark -updateUserProfileiPhoneDelegate

-(void)refreshiPUserProfile:(ATPrivateUserProfileModel *)newUserProfile{
    [self loadUserProfile:newUserProfile];
    [self selectSection:_currentOptionSelected];
}
-(void)reloadUserProfile
{
    //TODO: RECARGAR EL PERFIL ENTERO.
    [TAConnectionHelper requestToTAdvisorUrl:kUrlPrivateProfileData withParameters:nil delegate:self tag:102];
}

#pragma mark - ATConnectionHelperDelegate

- (void)responseWithData:(NSDictionary*)dataDict tag:(NSInteger)tag{
    if(tag ==102)
    {
        NSDictionary* data=[dataDict objectForKey:@"DATA"];
        NSError *error=nil;
        ATPrivateUserProfileModel *aux = [MTLJSONAdapter modelOfClass:[ATPrivateUserProfileModel class] fromJSONDictionary:data error:&error];
        aux.notificationSummary=self.userProfile.notificationSummary;
        [(ATAppDelegate*)[[UIApplication sharedApplication] delegate] setUserPrivateProfile:aux];
        [self refreshiPUserProfile:aux];
        //[self asyncLoad];
    }
}
- (void)responseWitError:(NSError*)error textError:(NSString*)textError dictionaryError:(NSDictionary*)errorDict tag:(NSInteger)tag{
    if (tag==102){
        UIAlertView* alert=[[UIAlertView alloc] initWithTitle:[TAHelperText getText:@"Alrt_Alert"] message:[TAHelperText getText:@"Alrt_ErrorReg"] delegate:nil cancelButtonTitle:[TAHelperText getText:@"Alrt_Ok"] otherButtonTitles: nil];
        [alert show];
    }
}

#pragma mark - ATiPNavigationMenuDelegate

- (void)didSelectItemAtIndex:(NSUInteger)index
{
    switch (index) {
        case 2:
            [self selectSection:Social];
            break;
        case 0:
            [self selectSection:Profiles];
            break;
        case 4:
            [self selectSection:Achivements];
            break;
        case 1:
            [self selectSection:Portfolios];
            break;
        case 5:
            [self selectSection:UserRanking];
            break;
        case 6:
            [self selectSection:PortfolioRanking];
            break;
        default:
            [self selectSection:Portfolios];
            break;
    }


    NSLog(@"did selected item at index %lu", (unsigned long)index);
}

@end

I don't know if I can have the same containers in the same screen and hide de containerPerfil when select something in the menu or what can be the best solution.

Thanks

Upvotes: 0

Views: 55

Answers (1)

ivan180593
ivan180593

Reputation: 54

You can use UISplitViewController.

UISplitViewController shows the items to the left of the screen and right information about the selected item (only if you are using an iPad in landscape). If you are using an iPhone or an iPad in portrait, first show your items. And if you select an item, you can see the details.

Upvotes: 1

Related Questions