How do I add multiple ViewControllers to my UIPageViewController? - objective-c

so I'm pretty new to Obj-C and have tried looking at sample code and other online resources to answer my question, but I can't seem to find anything that really helps. Essentially what I'm trying to do is to add multiple UIViewControllers that I created in Storyboard to a UIPageViewController - the first place I looked to for help was Xcode itself by using a template of a PageBased application. That actually helped quite a lot and I got a PageController up and running. Then I turned to online resources but most (if not all of them) use a single viewController (like this). Then I turned to StackOverflow and found the following - How to implement UIPageViewController that utilizes multiple ViewControllers.
The above resources got me this far:
In PageViewController.h:
#import <UIKit/UIKit.h>
#interface PageViewController : UIPageViewController <UIPageViewControllerDataSource>
#end
In PageViewController.m:
#import "PageViewController.h"
#interface PageViewController ()
#end
#implementation PageViewController {
NSArray *viewControllers;
UIViewController *first;
UIViewController *second;
UIViewController *third;
UIViewController *fourth;
UIViewController *fifth;
}
- (UIViewController *)first {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
first = [sb instantiateViewControllerWithIdentifier:#"1"];
return first;
}
- (UIViewController *)second {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
second = [sb instantiateViewControllerWithIdentifier:#"2"];
return second;
}
- (UIViewController *)third {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
third = [sb instantiateViewControllerWithIdentifier:#"3"];
return third;
}
- (UIViewController *)fourth {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
fourth = [sb instantiateViewControllerWithIdentifier:#"4"];
return fourth;
}
- (UIViewController *)fifth {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
fifth = [sb instantiateViewControllerWithIdentifier:#"5"];
return fifth;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSource = self;
// Aggancio il view controller iniziale.
[self setViewControllers:#[self.first]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *nextViewController = nil;
if (viewController == self.first) {
nextViewController = self.second;
}
if (viewController == self.second) {
nextViewController = self.third;
}
if (viewController == self.third) {
nextViewController = self.fourth;
}
if (viewController == fourth) {
nextViewController = self.fifth;
}
return nextViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *prevViewController = nil;
if (viewController == self.fifth) {
prevViewController = self.fourth;
}
if (viewController == self.fourth) {
prevViewController = self.third;
}
if (viewController == self.third) {
prevViewController = self.second;
}
if (viewController == self.second) {
prevViewController = self.first;
}
return prevViewController;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
All this code does is load the first view controller which is now swipe-able, but doesn't actually swipe towards anything - why is this?. What am I doing wrong? The aforementioned resources used titles and pages to create views and I really don't know how to go about this. Would anyone mind guiding me or nudging me in the correct direction? Any help would be greatly appreciated. Thanks!

Here is the fully working code if anyone is interested. Took me a while to get it right, but eventually this worked perfectly!
#import "PageViewController.h"
#interface PageViewController ()
#property (nonatomic, retain) UIViewController *first;
#property (nonatomic, retain) UIViewController *second;
#property (nonatomic, retain) UIViewController *third;
#property (nonatomic, retain) UIViewController *fourth;
#property (nonatomic, retain) UIViewController *fifth;
#end
#implementation PageViewController {
NSArray *viewControllers;
}
- (UIViewController *)first {
if (!_first) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_first = [sb instantiateViewControllerWithIdentifier:#"1"];
}
return _first;
}
- (UIViewController *)second {
if (!_second) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_second = [sb instantiateViewControllerWithIdentifier:#"2"];
}
return _second;
}
- (UIViewController *)third {
if (!_third) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_third = [sb instantiateViewControllerWithIdentifier:#"3"];
}
return _third;
}
- (UIViewController *)fourth {
if (!_fourth) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_fourth = [sb instantiateViewControllerWithIdentifier:#"4"];
}
return _fourth;
}
- (UIViewController *)fifth {
if (!_fifth) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_fifth = [sb instantiateViewControllerWithIdentifier:#"5"];
}
return _fifth;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSource = self;
// Aggancio il view controller iniziale.
[self setViewControllers:#[self.first]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *nextViewController = nil;
if (viewController == self.first) {
nextViewController = self.second;
}
if (viewController == self.second) {
nextViewController = self.third;
}
if (viewController == self.third) {
nextViewController = self.fourth;
}
if (viewController == self.fourth) {
nextViewController = self.fifth;
}
return nextViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *prevViewController = nil;
if (viewController == self.fifth) {
prevViewController = self.fourth;
}
if (viewController == self.fourth) {
prevViewController = self.third;
}
if (viewController == self.third) {
prevViewController = self.second;
}
if (viewController == self.second) {
prevViewController = self.first;
}
return prevViewController;
}
#end

This is old, but it helped me out a lot. For some reason your code had some problems for me, and I wasn't using storyboard. For anyone's future reference, this is the code I'm using that works:
#import "PageController.h"
#import "SeasonTixViewController.h"
#import "SeasonTicketPricesViewController.h"
#import "ArenaLayoutSeasonTixViewController.h"
#interface PageController ()
#property (nonatomic, retain) UIViewController *first;
#property (nonatomic, retain) UIViewController *second;
#property (nonatomic, retain) UIViewController *third;
#end
#implementation PageController {
NSArray *viewControllers;
}
- (UIViewController *)first {
if (!_first) {
SeasonTixViewController *first = [[SeasonTixViewController alloc] init];
_first = first;
}
return _first;
}
- (UIViewController *)second {
if (!_second) {
SeasonTicketPricesViewController *second = [[SeasonTicketPricesViewController alloc] init];
_second = second;
}
return _second;
}
- (UIViewController *)third {
if (!_third) {
ArenaLayoutSeasonTixViewController *third = [[ArenaLayoutSeasonTixViewController alloc] init];
_third = third;
}
return _third;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
[[self.pageController view] setFrame:self.view.bounds];
self.pageController.dataSource = self;
[self.pageController setViewControllers:#[self.first]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *nextViewController = nil;
if (viewController == self.first) {
nextViewController = self.second;
}
if (viewController == self.second) {
nextViewController = self.third;
}
return nextViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *prevViewController = nil;
if (viewController == self.third) {
prevViewController = self.second;
}
if (viewController == self.second) {
prevViewController = self.first;
}
return prevViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return 3;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return 0;
}
#end

Related

UIPageviewcontroller: starting in the middle

Unfortunately the search didn't help me out... I have the following problem: I have three UItableviews (ViewController1, ViewController2 and Viewcontroller3) which I embedded in a simple PageViewController Screenshot of storyboard ( I can't insert any pictures here yet :/).
In order to display the three ViewControllers I put them into an array in my viewdidload in my PageViewController.m (custom class for the PageViewController), so I didn't use a ViewController as a Container to lod the other ViewControllers into:
-(void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"TableView1"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"TableView2"];
UIViewController *p3 = [self.storyboard
instantiateViewControllerWithIdentifier:#"TableView3"];
myViewControllers = #[p1,p2,p3];
I can pick which viewcontroller I start with and either
- go forwards(direction:UIPageViewControllerNavigation**DirectionForward**):
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
NSLog(#"loaded!");
}
or pick the last on and go backwards (UIPageViewControllerNavigation**DirectionReverse**):
[self setViewControllers:#[p3]
direction:UIPageViewControllerNavigationDirectionReverse
animated:NO completion:nil];
However, I've been trying to figure out how to start with ViewController2 and have Viewcontroller1 on its left and ViewController3 on the right (cp. Screenshot)
Any suggestions or code snippets would be hugely appreciated!
And here's the entire code:
#import "StartScreenPageViewController.h"
#interface StartScreenPageViewController ()
#end
#implementation StartScreenPageViewController
{
NSArray *myViewControllers;
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"1"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"2"];
UIViewController *p3 = [self.storyboard
instantiateViewControllerWithIdentifier:#"3"];
myViewControllers = #[p1,p2,p3];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
NSLog(#"loaded!");
}
-(UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
return myViewControllers[index];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
--currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
++currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(NSInteger)presentationCountForPageViewController:
(UIPageViewController *)pageViewController
{
return myViewControllers.count;
}
-(NSInteger)presentationIndexForPageViewController:
(UIPageViewController *)pageViewController
{
return 0;
}
#end
You should be able to set the initial view controller in viewDidLoad. You're already doing it, but you're setting it to the first view controller:
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
I think you should just be able to change this to:
[self setViewControllers:#[p2]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
Then just make sure your pageViewController:viewControllerAfterViewController and pageViewController:viewControllerBeforeViewController methods handle iterating up and down the data source per your desired functionality.

presentViewController with storyboards shows black view iOS 7.1 xcode 5.1

i did search SO and the web didn't find amy answer .
i created in storyboard main UITableViewController called A which have simple button.
and another ViewController Called B which have webView and close button.
that is not connected in any form to the main UITableViewController A
now i like to open the B viewController form A and then close the B ViewController with its own close button .
but what ever i try the B view controller is black and blank .
ViewController B ( the popup view )
#import "TAFBLoginDialogViewController.h"
#interface TAFBLoginDialogViewController ()
#end
#implementation TAFBLoginDialogViewController
-(id)initWithAppId:(NSString *)apiKey
requestPremision:(NSString *)requestPremision
delegate:(id<TAFBLoginDialogViewdelegate>)delegate
storyBoardName:(NSString*) storyBoardName
{
//self = [super initWithNibName:#"FBLoginDialog" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"FBLoginDialog"];
if (self) {
// Custom initialization
self.apiKey = apiKey;
self.requestPremision = requestPremision;
self.delegate = delegate;
}
return self;
}
- (IBAction)closeTap:(id)sender
{
[self.delegate closeTaped];
}
-(void)login
{
}
-(void)logout
{
}
-(void)checkForAccessToken:(NSString*)urlString
{
}
-(void)checkLoginRequired:(NSString*)urlString
{
[self.delegate displayRequired];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
UITableViewController A ( the main view controller from which i try to open B)
#import "TAFMETableViewController.h"
#interface TAFMETableViewController ()
{
}
#end
#implementation TAFMETableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
-(void) awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return cell;
}
- (IBAction)handleOpenFBDialog:(id)sender {
UIStoryboard * storyboard = self.storyboard;
NSString * storyboardName = [storyboard valueForKey:#"name"];
self.appId = #"11111";
self.permissions =#"public_stream";
if(_loginDialogView ==nil)
{
self.LoginDialogViewController = [[TAFBLoginDialogViewController alloc] initWithAppId:_appId
requestPremision:_permissions
delegate:self storyBoardName:storyboardName];
self.loginDialogView = _LoginDialogViewController.view;
}
[self.LoginDialogViewController checkLoginRequired:#"tst"];
NSLog(#"Click!");
}
-(void)accessTokenFound:(NSString*)accessToken
{
NSLog(#"accessTokenFound Click!");
}
-(void)displayRequired
{
NSLog(#"displayRequired Click!");
[self presentViewController:_LoginDialogViewController animated:YES completion:nil];
}
-(void)closeTaped
{
NSLog(#"closeTaped Click!");
[self dismissViewControllerAnimated:NO completion:nil];
}
#end
header file :
#protocol TAFBLoginDialogViewdelegate
-(void)accessTokenFound:(NSString*)accessToken;
-(void)displayRequired;
-(void)closeTaped;
#end
#interface TAFBLoginDialogViewController : UIViewController<UIWebViewDelegate>
{
//ivars
// UIWebView *_webview;
// NSString* _apiKey;
// NSString* _requestPremision;
// id <TAFBLoginDialogViewdelegate> _delegate;
}
#property (retain) IBOutlet UIWebView *webView;
#property (copy) NSString *apiKey;
#property (copy) NSString *requestPremision;
#property (assign) id<TAFBLoginDialogViewdelegate> delegate;
-(id)initWithAppId:(NSString*)apiKey
requestPremision:(NSString*)requestPremision
delegate:(id<TAFBLoginDialogViewdelegate>)delegate
storyBoardName:(NSString*) storyBoardName;
- (IBAction)closeTap:(id)sender;
-(void)login;
-(void)logout;
-(void)checkForAccessToken:(NSString*)urlString;
-(void)checkLoginRequired:(NSString*)urlString;
#end
I have button in the TableView A that trigger :
- (IBAction)handleOpenFBDialog:(id)sender
then this function init the ViewController B
and the invoking :
[self.LoginDialogViewController checkLoginRequired:#"tst"];
which supposed to show the ViewController B
but all it does shows black screen .
in your initWithAppID method you instantiate your view controller from the storyboard and then don't do anything with it. Then you have an if (self) initialization block but you've never initialized self.
It looks like what you want to do is set self equal to the view controller that you instantiated from the storyboard and then set the properties on it.
It might make more sense to make this a class method instead since your allocating a view controller object and inside it's init method your creating another one from the storyboard and ignoring the one you allocated.
+(instancetype) TAFBLoginDialogViewControllerWithAppID:(NSString *)apiKey
requestPremision:(NSString *)requestPremision
delegate:(id<TAFBLoginDialogViewdelegate>)delegate
storyBoardName:(NSString*) storyBoardName
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
TAFBLoginDialogViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"FBLoginDialog"];
// Custom initialization
viewController.apiKey = apiKey;
viewController.requestPremision = requestPremision;
viewController.delegate = delegate;
return viewController;
}

How can i move to myScene from UIViewController?

I have 2 viewcontroller. In the first viewcontroller, there is the introduction and logo of the game and in the second viewcontroller it loads the skscene. And I travel from my first viewcontroller to second viewcontroller with a button click. But it becones error. My code is in the second viewcontroller is:
#interface MPAPViewSceneController()
#property (nonatomic, retain) MPAPMyScene *targetScene;
#property SKView *spriteView;
#end
- (void)viewDidLoad
{
[super viewDidLoad];
_spriteView = (SKView *)self.view;
_spriteView.showsFPS = YES;
_spriteView.showsNodeCount = YES;
_spriteView.showsDrawCount = YES;
}
-(void)viewWillAppear:(BOOL)animated {
self.targetScene = [[MPAPMyScene alloc] initWithSize:CGSizeMake(768.0f, 1024.0f)];
[_spriteView presentScene:self.targetScene];
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:YES];
self.targetScene = nil;
}
And in the scene I have written the code given below:
#interface MPAPMyScene()
#property (nonatomic) BOOL contentCreated;
#end
#implementation MPAPMyScene
-(void)didMoveToView:(SKView *)view {
if (self.contentCreated == NO) {
[self createSceneContents];
self.contentCreated = YES;
}
}
-(void)willMoveFromView:(SKView *)view {
[self removeAllChildren];
}
-(void)createSceneContents {
self.backgroundColor = [UIColor blueColor];
self.scaleMode = SKSceneScaleModeAspectFit;
}
Try changing this
_spriteView = (SKView *)self.view;
to
_spriteView = (SKView *)self.targetScene;

How to navigate from UIView to UIViewController

i am aware that uiview does not have navigational control. Thus, i am not able to push from the uiview to the next uiviewcontroller.
here is the code of my method. Please help. Thanks!
- (void)scrollViewDoubleTapped:(UITapGestureRecognizer*)recognizer {
CGPoint pointInView = [recognizer locationInView:self];
NSLog(#"%f , %f",pointInView.x,pointInView.y);
if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (193) && pointInView.y <=(218)) )
{
// how to push to next viewcontroller here?
UIView *view = [UIGestureRecognizer view]; //what should i do for this code?
[self viewController];
}
}
-(TestViewViewController*)viewController
{
for (UIView *next = [self superview]; next; next = next.superview)
{
UIResponder *nextResponder = [next nextResponder];
if([nextResponder isKindOfClass:[TestViewViewController class]])
{
return (TestViewViewController*)nextResponder;
}
}
return nil;
}
If you want to get viewcontroller having a view than you can use nextResponder method
So first you get the view from gestureRecognizer:
UIView *view = [gestureRecognizer view];
and than search for the viewcontroller containing the view
Look here
Edit:
if ((pointInView.x >= (231.0) && pointInView.x <=(293) && pointInView.y >= (193) && pointInView.y <=(218)) )
{
// how to push to next viewcontroller here?
UIView *view = [recognizer view]; //what should i do for this code?
UIViewController *viewController = [self getViewControllerFromView:view];
if(viewController) {
// do whatever you want...
UIViewController *newViewController = ...
[viewController.navigationController pushViewController:newViewController animated:YES];
}
}
...
I rewrote method get ViewController to your case. To get it from some view:
-(UIViewController*)getViewControllerFromView:(UIView*) view
{
if([[view nextResponder] isKindOfClass:[UIViewController class]])
{
return (UIViewController*)[view nextResponder];
}
else {
for (UIView *next = [view superview]; next; next = next.superview)
{
UIResponder *nextResponder = [next nextResponder];
if([nextResponder isKindOfClass:[UIViewController class]])
{
return (UIViewController*)nextResponder;
}
}
}
return nil;
}
new edit::
your EAGLView has #property (nonatomic, retain) UIViewController *viewController;
ADD #synthesize viewController = _viewController; to .m file.
CoreMotionAppDelegate::
MainViewController * itemsViewController = [[MainViewController alloc]init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:itemsViewController];
glView.viewController = itemsViewController;
[glView startAnimation];
[[self window]setRootViewController:navController];
And than in your scrollViewDoubleTapped method just
EAGLView *v = (EAGLView*)[recognizer view];
UIViewController *viewController = v.viewController;

Works on iPad Simulator but crashes on iPad

Hi I am trying to develop a new app on the ipad. I am using a spitTableView and adding a ModalPresentationPage to the view. This works perfectly on the xcode iPad sim but crashes on my iPad. just so you know I am using xcode 5BATA and running IOS 5 on my iPad.
here is my code
DetailViewController.h
#import <UIKit/UIKit.h>
#interface DetailViewController : UIViewController <UISplitViewControllerDelegate>{
}
-(IBAction)loadView:(id)sender;
#property (strong, nonatomic) id detailItem;
#property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
#property (strong, nonatomic) IBOutlet UIToolbar *toolbar;
#end
DetailViewController.m
#import "DetailViewController.h"
#import "ModalViewController.h"
#import "RootViewController.h"
#interface DetailViewController ()
#property (strong, nonatomic) UIPopoverController *popoverController;
- (void)configureView;
#end
#implementation DetailViewController
#synthesize detailItem = _detailItem;
#synthesize detailDescriptionLabel = _detailDescriptionLabel;
#synthesize toolbar = _toolbar;
#synthesize popoverController = _myPopoverController;
-(IBAction)loadView:(id)sender{
ModalViewController *mvc = [[ModalViewController alloc]initWithNibName:#"modalViewController"bundle:nil];
mvc.modalPresentationStyle = UIModalPresentationPageSheet;
mvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:mvc animated:YES];
}
- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
}
return self;
}
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.popoverController != nil) {
[self.popoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
self.splitViewController.delegate = self;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
#pragma mark - Split view
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController: (UIPopoverController *)pc
{
barButtonItem.title = #"Master";
NSMutableArray *items = [[self.toolbar items] mutableCopy];
[items insertObject:barButtonItem atIndex:0];
[self.toolbar setItems:items animated:YES];
self.popoverController = pc;
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
NSMutableArray *items = [[self.toolbar items] mutableCopy];
[items removeObjectAtIndex:0];
[self.toolbar setItems:items animated:YES];
self.popoverController = nil;
}
#end
Parts not under NDA :-
You are leaking items in both the split view delegate methods.
Are you sure the XIB name is modalViewController? There could a problem of it being case sensitive on the device.