Simplify example by using storyboard reference

This commit is contained in:
Mike Enriquez + Leon Gersing
2012-02-29 19:24:00 -05:00
parent 952ea470bc
commit 9692195b42
6 changed files with 12 additions and 53 deletions

View File

@@ -21,20 +21,12 @@
self.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;
self.view.clipsToBounds = NO;
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
if (![self.slidingViewController.underRightViewController isKindOfClass:[UnderRightViewController class]]) {
self.slidingViewController.underRightViewController = [storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
self.slidingViewController.underRightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
}
[self.view addGestureRecognizer:self.slidingViewController.panGesture];

View File

@@ -48,14 +48,8 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = [NSString stringWithFormat:@"%@Top", [self.menuItems objectAtIndex:indexPath.row]];
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
UIViewController *newTopViewController = [storyboard instantiateViewControllerWithIdentifier:identifier];
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;

View File

@@ -14,20 +14,12 @@
{
[super viewWillAppear:animated];
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
if (![self.slidingViewController.underRightViewController isKindOfClass:[UnderRightViewController class]]) {
self.slidingViewController.underRightViewController = [storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
self.slidingViewController.underRightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
}
[self.view addGestureRecognizer:self.slidingViewController.panGesture];

View File

@@ -15,15 +15,7 @@
[super viewWillAppear:animated];
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
self.slidingViewController.underRightViewController = nil;
self.slidingViewController.anchorLeftPeekAmount = 0;

View File

@@ -14,20 +14,12 @@
{
[super viewWillAppear:animated];
UIStoryboard *storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
if (![self.slidingViewController.underRightViewController isKindOfClass:[UnderRightViewController class]]) {
self.slidingViewController.underRightViewController = [storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
self.slidingViewController.underRightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UnderRight"];
}
[self.view addGestureRecognizer:self.slidingViewController.panGesture];

View File

@@ -40,9 +40,8 @@ You'll need these four files:
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`
ECSlidingViewController *slidingViewController = (ECSlidingViewController *)self.window.rootViewController;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
slidingViewController.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];
slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstTop"];
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".
@@ -61,10 +60,8 @@ Below is the `viewWillAppear:` method for `FirstTopViewController`.
{
[super viewWillAppear:animated];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
if (![self.slidingViewController.underLeftViewController isKindOfClass:[MenuViewController class]]) {
self.slidingViewController.underLeftViewController = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
}
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
@@ -109,4 +106,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.