Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions YSLContainerViewController/YSLChildViewControllerDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// YSLChildViewControllerDelegate.h
// YSLContainerViewControllerDemo
//
// Created by Romy on 6/19/15.
// Copyright © 2015 h.yamaguchi. All rights reserved.
//

@import UIKit;

/*
* Delegate so child view controller can communicate with grandparent YSLContainerViewController
*/
@protocol YSLChildViewControllerDelegate <NSObject>

// Child view controller selects a value, moves it to the appropriate index in the container view
- (void)childViewController:(UIViewController *)childViewController
didChooseIndexValue:(NSInteger)value;

@end
3 changes: 2 additions & 1 deletion YSLContainerViewController/YSLContainerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
//

#import <UIKit/UIKit.h>
#import "YSLChildViewControllerDelegate.h"

@protocol YSLContainerViewControllerDelegate <NSObject>

- (void)containerViewItemIndex:(NSInteger)index currentController:(UIViewController *)controller;

@end

@interface YSLContainerViewController : UIViewController
@interface YSLContainerViewController : UIViewController <YSLChildViewControllerDelegate>

@property (nonatomic, weak) id <YSLContainerViewControllerDelegate> delegate;

Expand Down
9 changes: 9 additions & 0 deletions YSLContainerViewController/YSLContainerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,13 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
[self setChildViewControllerWithCurrentIndex:self.currentIndex];
}

#pragma mark - YSLChildViewControllerDelegate

- (void)childViewController:(UIViewController *)childViewController
didChooseIndexValue:(NSInteger)value {
if (value != self.currentIndex && value < self.childControllers.count) {
[self scrollMenuViewSelectedIndex:value];
}
}

@end
2 changes: 2 additions & 0 deletions YSLContainerViewControllerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
D0DD9FBF1AFCB67E002CEBB6 /* YSLContainerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YSLContainerViewController.m; sourceTree = "<group>"; };
D0DD9FC01AFCB67E002CEBB6 /* YSLScrollMenuView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YSLScrollMenuView.h; sourceTree = "<group>"; };
D0DD9FC11AFCB67E002CEBB6 /* YSLScrollMenuView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YSLScrollMenuView.m; sourceTree = "<group>"; };
EC861EF71B34BDB0006129DF /* YSLChildViewControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YSLChildViewControllerDelegate.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -227,6 +228,7 @@
D0DD9FBD1AFCB67E002CEBB6 /* YSLContainerViewController */ = {
isa = PBXGroup;
children = (
EC861EF71B34BDB0006129DF /* YSLChildViewControllerDelegate.h */,
D0DD9FBE1AFCB67E002CEBB6 /* YSLContainerViewController.h */,
D0DD9FBF1AFCB67E002CEBB6 /* YSLContainerViewController.m */,
D0DD9FC01AFCB67E002CEBB6 /* YSLScrollMenuView.h */,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions YSLContainerViewControllerDemo/ArtistsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//

#import <UIKit/UIKit.h>
#import "YSLChildViewControllerDelegate.h"

@interface ArtistsViewController : UITableViewController

@property (weak, nonatomic) id <YSLChildViewControllerDelegate> delegate;

@end
3 changes: 2 additions & 1 deletion YSLContainerViewControllerDemo/ArtistsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return _artistsArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- (UITableViewCell *)tableView:(UITableView *)tableView
scellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"ArtistsCell";
ArtistsCell *cell = (ArtistsCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

Expand Down
5 changes: 3 additions & 2 deletions YSLContainerViewControllerDemo/ArtistsViewController.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8121.17" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ArtistsViewController">
Expand Down
3 changes: 3 additions & 0 deletions YSLContainerViewControllerDemo/DetailViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//

#import <UIKit/UIKit.h>
#import "YSLChildViewControllerDelegate.h"

@interface DetailViewController : UIViewController

@property (weak, nonatomic) id <YSLChildViewControllerDelegate> delegate;

@end
3 changes: 3 additions & 0 deletions YSLContainerViewControllerDemo/PlayListTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//

#import <UIKit/UIKit.h>
#import "YSLChildViewControllerDelegate.h"

@interface PlayListTableViewController : UITableViewController

@property (weak, nonatomic) id <YSLChildViewControllerDelegate> delegate;

@end
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8121.17" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PlayListTableViewController">
Expand Down
3 changes: 3 additions & 0 deletions YSLContainerViewControllerDemo/SampleViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//

#import <UIKit/UIKit.h>
#import "YSLChildViewControllerDelegate.h"

@interface SampleViewController : UIViewController

@property (weak, nonatomic) id <YSLChildViewControllerDelegate> delegate;

@end
9 changes: 8 additions & 1 deletion YSLContainerViewControllerDemo/SampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ - (void)didReceiveMemoryWarning {

- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"SampleViewController viewWillAppear");
[super viewWillAppear:animated];
}

- (void)viewDidLoad {
[super viewDidLoad];
}

- (IBAction)btnPressed:(id)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(childViewController:didChooseIndexValue:)]) {
// put it to index one for now
[self.delegate childViewController:self didChooseIndexValue:0];
}
}

@end
4 changes: 2 additions & 2 deletions YSLContainerViewControllerDemo/SampleViewController.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="13E28" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8121.17" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.14"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SampleViewController">
Expand Down
7 changes: 7 additions & 0 deletions YSLContainerViewControllerDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ - (void)viewDidLoad {
containerVC.delegate = self;
containerVC.menuItemFont = [UIFont fontWithName:@"Futura-Medium" size:16];

// delegates for the children
playListVC.delegate = containerVC;
artistVC.delegate = containerVC;
sampleVC1.delegate = containerVC;
sampleVC2.delegate = containerVC;
sampleVC3.delegate = containerVC;

[self.view addSubview:containerVC.view];
}

Expand Down