diff --git a/AnotherStoryboard.storyboard b/AnotherStoryboard.storyboard new file mode 100644 index 0000000..2f7c9e1 --- /dev/null +++ b/AnotherStoryboard.storyboard @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MSPageViewController.xcodeproj/project.pbxproj b/MSPageViewController.xcodeproj/project.pbxproj index 37968c3..f05911c 100644 --- a/MSPageViewController.xcodeproj/project.pbxproj +++ b/MSPageViewController.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 57EFFA8A18B159B5002E5577 /* MSPageViewControllerPage.m in Sources */ = {isa = PBXBuildFile; fileRef = 57EFFA8918B159B5002E5577 /* MSPageViewControllerPage.m */; }; 57EFFA8E18B15AC6002E5577 /* MSPageViewControllerExample.m in Sources */ = {isa = PBXBuildFile; fileRef = 57EFFA8D18B15AC6002E5577 /* MSPageViewControllerExample.m */; }; 57EFFA9018B15AD9002E5577 /* MSPageViewControllerExample.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 57EFFA8F18B15AD9002E5577 /* MSPageViewControllerExample.storyboard */; }; + 653D9C051A22362E00DCE4F5 /* AnotherStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 653D9C041A22362E00DCE4F5 /* AnotherStoryboard.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -60,6 +61,7 @@ 57EFFA8C18B15AC6002E5577 /* MSPageViewControllerExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MSPageViewControllerExample.h; path = Example/MSPageViewControllerExample.h; sourceTree = ""; }; 57EFFA8D18B15AC6002E5577 /* MSPageViewControllerExample.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MSPageViewControllerExample.m; path = Example/MSPageViewControllerExample.m; sourceTree = ""; }; 57EFFA8F18B15AD9002E5577 /* MSPageViewControllerExample.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = MSPageViewControllerExample.storyboard; path = Example/MSPageViewControllerExample.storyboard; sourceTree = ""; }; + 653D9C041A22362E00DCE4F5 /* AnotherStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = AnotherStoryboard.storyboard; path = ../AnotherStoryboard.storyboard; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -176,6 +178,7 @@ 57EFFA8C18B15AC6002E5577 /* MSPageViewControllerExample.h */, 57EFFA8D18B15AC6002E5577 /* MSPageViewControllerExample.m */, 57EFFA8F18B15AD9002E5577 /* MSPageViewControllerExample.storyboard */, + 653D9C041A22362E00DCE4F5 /* AnotherStoryboard.storyboard */, ); name = Example; sourceTree = ""; @@ -257,6 +260,7 @@ buildActionMask = 2147483647; files = ( 57EFFA9018B15AD9002E5577 /* MSPageViewControllerExample.storyboard in Resources */, + 653D9C051A22362E00DCE4F5 /* AnotherStoryboard.storyboard in Resources */, 57EFFA5C18B149F7002E5577 /* InfoPlist.strings in Resources */, 57EFFA6418B149F7002E5577 /* Images.xcassets in Resources */, ); diff --git a/MSPageViewController/Example/MSPageViewControllerExample.m b/MSPageViewController/Example/MSPageViewControllerExample.m index d197229..9a5550b 100644 --- a/MSPageViewController/Example/MSPageViewControllerExample.m +++ b/MSPageViewController/Example/MSPageViewControllerExample.m @@ -19,7 +19,7 @@ + (void)initialize { } - (NSArray *)pageIdentifiers { - return @[@"page1", @"page2", @"page3", @"page4"]; + return @[@"page1", @"page2", @"page3", @"page4", @"AnotherStoryboard:page5"]; } @end diff --git a/MSPageViewController/Example/MSPageViewControllerExample.storyboard b/MSPageViewController/Example/MSPageViewControllerExample.storyboard index f38f3eb..9ca0cc2 100644 --- a/MSPageViewController/Example/MSPageViewControllerExample.storyboard +++ b/MSPageViewController/Example/MSPageViewControllerExample.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -18,7 +19,6 @@ \ No newline at end of file + diff --git a/MSPageViewController/Images.xcassets/AppIcon.appiconset/Contents.json b/MSPageViewController/Images.xcassets/AppIcon.appiconset/Contents.json index a396706..33ec0bc 100644 --- a/MSPageViewController/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/MSPageViewController/Images.xcassets/AppIcon.appiconset/Contents.json @@ -14,6 +14,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" } ], "info" : { diff --git a/MSPageViewController/Source/MSPageViewController+Protected.h b/MSPageViewController/Source/MSPageViewController+Protected.h index 4f1e1a4..0832866 100644 --- a/MSPageViewController/Source/MSPageViewController+Protected.h +++ b/MSPageViewController/Source/MSPageViewController+Protected.h @@ -34,4 +34,17 @@ */ - (UIViewController *)viewControllerAtIndex:(NSInteger)index; +/** + * @note Can be overridden. + * @discussion Storyboard factory. May be overriden to provide TyphoonStoryboard instance + */ +- (UIStoryboard *)storyboardWithName:(NSString *)name index:(NSInteger) storyboardIndex; + +/** + * @note Can be overridden. + * @discussion Controller factory. + */ + +- (UIViewController *)instantiateViewControllerWithIdentifier:(NSString*)identifier storyboard:(UIStoryboard*) fromStoryboard; + @end diff --git a/MSPageViewController/Source/MSPageViewController.m b/MSPageViewController/Source/MSPageViewController.m index 880af8b..d8462e2 100644 --- a/MSPageViewController/Source/MSPageViewController.m +++ b/MSPageViewController/Source/MSPageViewController.m @@ -52,6 +52,14 @@ - (void)setUpViewController:(UIViewController *)viewC } +- (UIStoryboard *)storyboardWithName:(NSString *)name index:(NSInteger) storyboardIndex { + return [UIStoryboard storyboardWithName: name bundle: nil]; +} + +- (UIViewController *)instantiateViewControllerWithIdentifier:(NSString*)identifier storyboard:(UIStoryboard*) fromStoryboard { + return [fromStoryboard instantiateViewControllerWithIdentifier:identifier]; +} + #pragma mark - - (void)viewDidLoad { @@ -92,7 +100,7 @@ - (UIViewController *)viewControllerAtIndex:(NSInteger)index { NSAssert(self.storyboard, @"This controller is only meant to be used inside of a UIStoryboard"); - result = [self.storyboard instantiateViewControllerWithIdentifier:self.pageIdentifiers[(NSUInteger)index]]; + result = [self instantiateViewController: self.pageIdentifiers[(NSUInteger)index] withIndex:index]; NSParameterAssert(result); NSAssert([result conformsToProtocol:@protocol(MSPageViewControllerChild)], @@ -119,4 +127,25 @@ - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)page return [pageViewController.viewControllers.lastObject pageIndex]; } +#pragma mark ViewController instantiation +-(UIViewController *)instantiateViewController:(NSString*)identifier withIndex: (NSInteger) index { + UIViewController *result = nil; + + UIStoryboard* storyboard = self.storyboard; + + NSArray* storyboardAndIdentifier = [identifier componentsSeparatedByString: @":"]; + + if (storyboardAndIdentifier.count == 2) { + storyboard = [self storyboardWithName: storyboardAndIdentifier[0] index: index]; + identifier = storyboardAndIdentifier[1]; + NSAssert(storyboard, @"Unable to find specified Storyboard by name"); + NSAssert([identifier length] > 0, @"Specified identified should not be empty"); + } + result = (UIViewController*)[self instantiateViewControllerWithIdentifier:identifier storyboard: storyboard]; + + NSParameterAssert(result); + return result; +} + + @end diff --git a/README.md b/README.md index 5bd79fc..03799a1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ With ```MSPageViewController``` you will be able to design each page from a sing First you must create a [subclass of ```MSPageViewController```](MSPageViewController/Source/MSPageViewController+Protected.h) and override ```-pageIdentifiers```. Example: ```objc - (NSArray *)pageIdentifiers { - return @[@"page1", @"page2"]; + return @[@"page1", @"page2", @"AnotherStoryboard:page3"]; } ``` @@ -19,6 +19,12 @@ Then you have to create a storyboard, add a ```UIPageViewController``` object an 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)). +You might specify Storyboard name using colon +``` +StoryBoardName:pageIdentifier +``` +Also, you can specify bunlde. In order to do that you have to override ```- (NSBundle*)storyboardBundleForIndex:(NSInteger)index``` + When your controller is instantiated, it will use these controllers to create each page. Make sure you also check out the sample project in this repo.