Skip to content

Commit 9692195

Browse files
author
Mike Enriquez + Leon Gersing
committed
Simplify example by using storyboard reference
1 parent 952ea47 commit 9692195

File tree

6 files changed

+12
-53
lines changed

6 files changed

+12
-53
lines changed

ECSlidingViewController/FirstTopViewController.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,12 @@ - (void)viewWillAppear:(BOOL)animated
2121
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
2222
self.view.clipsToBounds = NO;
2323

24-
UIStoryboard *storyboard;
25-
26-
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
27-
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
28-
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
29-
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
30-
}
31-
3224
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
33-
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
25+
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
3426
}
3527

3628
if (![self.slidingViewController.underRightViewController isKindOfClass:[UnderRightViewController class]]) {
37-
self.slidingViewController.underRightViewController = [storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
29+
self.slidingViewController.underRightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
3830
}
3931

4032
[self.view addGestureRecognizer:self.slidingViewController.panGesture];

ECSlidingViewController/MenuViewController.m

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
4848
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
4949
{
5050
NSString *identifier = [NSString stringWithFormat:@"%@Top", [self.menuItems objectAtIndex:indexPath.row]];
51-
UIStoryboard *storyboard;
52-
53-
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
54-
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
55-
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
56-
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
57-
}
58-
UIViewController *newTopViewController = [storyboard instantiateViewControllerWithIdentifier:identifier];
51+
52+
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
5953

6054
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
6155
CGRect frame = self.slidingViewController.topViewController.view.frame;

ECSlidingViewController/NavigationTopViewController.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ - (void)viewWillAppear:(BOOL)animated
1414
{
1515
[super viewWillAppear:animated];
1616

17-
UIStoryboard *storyboard;
18-
19-
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
20-
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
21-
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
22-
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
23-
}
24-
2517
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
26-
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
18+
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
2719
}
2820

2921
if (![self.slidingViewController.underRightViewController isKindOfClass:[UnderRightViewController class]]) {
30-
self.slidingViewController.underRightViewController = [storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
22+
self.slidingViewController.underRightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
3123
}
3224

3325
[self.view addGestureRecognizer:self.slidingViewController.panGesture];

ECSlidingViewController/SecondTopViewController.m

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ - (void)viewWillAppear:(BOOL)animated
1515
[super viewWillAppear:animated];
1616

1717
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
18-
UIStoryboard *storyboard;
19-
20-
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
21-
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
22-
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
23-
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
24-
}
25-
26-
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
18+
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
2719
}
2820
self.slidingViewController.underRightViewController = nil;
2921
self.slidingViewController.anchorLeftPeekAmount = 0;

ECSlidingViewController/ThirdTopViewController.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@ - (void)viewWillAppear:(BOOL)animated
1414
{
1515
[super viewWillAppear:animated];
1616

17-
UIStoryboard *storyboard;
18-
19-
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
20-
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
21-
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
22-
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
23-
}
24-
2517
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
26-
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
18+
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
2719
}
2820

2921
if (![self.slidingViewController.underRightViewController isKindOfClass:[UnderRightViewController class]]) {
30-
self.slidingViewController.underRightViewController = [storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
22+
self.slidingViewController.underRightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
3123
}
3224

3325
[self.view addGestureRecognizer:self.slidingViewController.panGesture];

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ You'll need these four files:
4040
Add a UIViewController to your storyboards and set the subclass to `ECSlidingViewController`. Then, you'll need to configure the instance of this view controller by setting a `topViewController`
4141

4242
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;
43-
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
4443
45-
slidingViewController.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];
44+
slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];
4645

4746
In this example, we can get a reference to the `ECSlidingViewController` instance then, we set the `topViewController` with an instance of a `UIViewController` subclass called `FirstTopViewController` that is identified as "FirstTop".
4847

@@ -61,10 +60,8 @@ Below is the `viewWillAppear:` method for `FirstTopViewController`.
6160
{
6261
[super viewWillAppear:animated];
6362
64-
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
65-
6663
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
67-
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
64+
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
6865
}
6966
7067
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
@@ -109,4 +106,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
109106
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
110107
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
111108
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
112-
SOFTWARE.
109+
SOFTWARE.

0 commit comments

Comments
 (0)