Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
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
5 changes: 1 addition & 4 deletions MSPageViewController/Source/MSPageViewController+Protected.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#import "MSPageViewController.h"

/**
* Subclassing notes:
* Child view controllers must conform to `MSPageViewControllerChild`.
*
* @see `MSPageViewControllerPage`.
*/
@interface MSPageViewController () <UIPageViewControllerDataSource>
Expand All @@ -26,7 +23,7 @@
/**
* Can be overriden to perform additional configuration on the controller.
*/
- (void)setUpViewController:(UIViewController<MSPageViewControllerChild> *)viewController
- (void)setUpViewController:(UIViewController *)viewController
atIndex:(NSInteger)index __attribute((objc_requires_super));

/**
Expand Down
6 changes: 0 additions & 6 deletions MSPageViewController/Source/MSPageViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@
@interface MSPageViewController : UIPageViewController

@end

@protocol MSPageViewControllerChild <NSObject>

@property (nonatomic) NSInteger pageIndex;

@end
17 changes: 7 additions & 10 deletions MSPageViewController/Source/MSPageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "MSPageViewController.h"
#import "MSPageViewController+Protected.h"
#import "UIViewController+MSPageViewController.h"

@implementation MSPageViewController

Expand Down Expand Up @@ -47,7 +48,7 @@ - (NSInteger)pageCount {
return (NSInteger)self.pageIdentifiers.count;
}

- (void)setUpViewController:(UIViewController<MSPageViewControllerChild> *)viewController
- (void)setUpViewController:(UIViewController *)viewController
atIndex:(NSInteger)index {

}
Expand All @@ -72,34 +73,30 @@ - (void)viewDidLoad {
#pragma mark - UIPageViewControllerDataSource

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController<MSPageViewControllerChild> *)viewController {
viewControllerBeforeViewController:(UIViewController *)viewController {
const NSInteger index = viewController.pageIndex;

return (index == NSNotFound) ? nil : [self viewControllerAtIndex:index - 1];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController<MSPageViewControllerChild> *)viewController {
viewControllerAfterViewController:(UIViewController *)viewController {
const NSInteger index = viewController.pageIndex;

return (index == NSNotFound) ? nil : [self viewControllerAtIndex:index + 1];
}

- (UIViewController *)viewControllerAtIndex:(NSInteger)index {
UIViewController<MSPageViewControllerChild> *result = nil;
UIViewController *result = nil;

if (index >= 0 && index < self.pageCount) {
NSAssert(self.storyboard,
@"This controller is only meant to be used inside of a UIStoryboard");

result = [self.storyboard instantiateViewControllerWithIdentifier:self.pageIdentifiers[(NSUInteger)index]];

NSParameterAssert(result);
NSAssert([result conformsToProtocol:@protocol(MSPageViewControllerChild)],
@"Child view controller (%@) must conform to %@",
result,
NSStringFromProtocol(@protocol(MSPageViewControllerChild)));


result.pageIndex = index;

[self setUpViewController:result
Expand Down
15 changes: 0 additions & 15 deletions MSPageViewController/Source/MSPageViewControllerPage.h

This file was deleted.

15 changes: 0 additions & 15 deletions MSPageViewController/Source/MSPageViewControllerPage.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UIViewController+MSPageViewController.h
// MSPageViewController
//
// Created by Christoph Keller on 04.12.14.
//

#import <UIKit/UIKit.h>

@interface UIViewController (MSPageViewController)

@property (nonatomic) NSInteger pageIndex;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// UIViewController+MSPageViewController.m
// MSPageViewController
//
// Created by Christoph Keller on 04.12.14.
//

#import "UIViewController+MSPageViewController.h"
#import <objc/runtime.h>

static char kMSPageViewControllerPageIndexKey;

@implementation UIViewController (MSPageViewController)

- (NSInteger)pageIndex {
NSNumber *number = (NSNumber *)objc_getAssociatedObject(self, &kMSPageViewControllerPageIndexKey);
return [number integerValue];
}

- (void)setPageIndex:(NSInteger)pageIndex {
objc_setAssociatedObject(self, &kMSPageViewControllerPageIndexKey, @(pageIndex), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ First you must create a [subclass of ```MSPageViewController```](MSPageViewContr

Then you have to create a storyboard, add a ```UIPageViewController``` object and change its class to ```MSPageViewController```.
Then you can add the controllers, setting their ```Storyboard ID```s to what you returned in ```pageIdentifiers```.
Each of them must be a class that conforms to ```MSPageViewControllerChild``` (if you don't need to add any extra functionality to it you can use [```MSPageViewControllerPage```](MSPageViewController/Source/MSPageViewControllerPage.h)).

When your controller is instantiated, it will use these controllers to create each page.

Expand Down