Next Page on click by page based application - ipad

In my page based application i want to perform the operation next page on click of button?Is it possible to to go next page using button in page based application?Pls help me to solve this issue
Edit: My application like story book im showing set of images in pages while turning next page, i want to show the nxt page by click

In your app the class conforms to the UIPageViewControllerDataSource protocol, make one object of this class in root view controller suppose ModelController then the object is _modelController.
Then in root view controller just put two UIButton connect them with appropriate IBAction methods suppose for previous button previousClick: and for next button nextClick:.
Now the code for each method is as follow:
-(IBAction)previousClick:(id)sender { [_modelController pageViewController:self.pageViewController viewControllerBeforeViewController:_dataViewController]; }
-(IBAction)nextClick:(id)sender { [_modelController pageViewController:self.pageViewController viewControllerAfterViewController:_dataViewController]; }
Here I suppose that the pageViewController is the one object of type UIPageViewController and is one of the declared and synthesized variable of root view controller, and also same for the _dataViewController which is one UIViewController contains one UIImageView to present the images on the root view.
EDIT
This also can be done with the using the DataViewController for that all the logic have to move to that view controller and all so the references must be needed for the UIPageViewController and ModelController.

Related

How to list all live (non-deallocated) UIViewControllers?

Some UIViewControllers do not seem to get deallocated.
What's the best way to list and identify all live (non-deallocated) UIViewControllers?
Run app in debugger and use "Debug memory graph" button and see the list of the view controllers in the panel on the left. If you happened to follow the convention of including ViewController in the name of your view controllers (e.g. MainViewController, DetailsViewController, etc.), you can filter the list of objects listed in the left panel by typing ViewController in the "filter" text box at the bottom of the left panel:
In this example, I also clicked on my third view controller, and I can see it was presented by the second one, which was presented by the first one.
The other approach is to use the "view debugger" , but that only shows the view controllers that are currently present in the active view controller hierarchy and may not show view controllers whose views are not currently visible because the view controller presented another view controller modally.
In addition to Rob's answer, if you want to see them initialized and deinitialized in real time you can print to console.
class Random32ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("32 did load")
}
deinit {
print("32 did deinit")
}
}
You can do this method on all class types beyond just view controllers.

how can I second time show my view controller without calling viewdidload?

here is my scenario case.
Initially for going to this VC without loading is hidden.when I click to first view controllers button it goes to second view controller.When I click button from secondVC it come back to first one and for going to this VC without loading button is now visible.Now when I click for going to this VC without loading I want to show my second view controller without reload because my previous loaded data for second view controller is needed.So how can I do that?
the actual scenario of my app look like this.My first VC
and the second one.
It's a picture of sound cloud but the case is same.
First possible solution,
Add SecondViewController as child view controller of FirstViewController using container view in Storyboard.
Every time you want to remove SecondViewController just hide/remove it with custom animation block.
Keep the reference of SecondViewController in FirstViewController
Second possible solution,
Create shared data object.
Then you can use that shared data object in any view controller, regardless of saving the state of any view controller.
I would create an object where i put the data und pass this from ViewController to ViewController by properties. Maybe this is to simple but it should work.

iOS - Will the ViewController be deallocated after it's been removed from the parent controller?

I'm working on a app with register/login.
My root controller is a UITabBarController.
Every tab is a view controller individually.
I want to make one of them a login tab.
Every time the app is launched and the user switches to this tab, it checks whether the user is logged in. If not, it presents a register controller while it presents a login controller when the user is logged in.
To implement the function, I wrote two view controllers separately (the register one and the log in one).
To obey the MVC style, I also make two UIView class to render the view.
To summarize, the structure is
root viewcontroller(UITabBarController) -> user tab controller(UIViewController) -> login/register view controller(UIViewController -> login/register view(UIView)
login/register controller is a childViewController of user tab controller.
After the user has registered, I want the register controller to be removed from the user tab controller, which is its parent controller.
As I handle the touch event in the view(UIView), I make a protocol in it and make the user tab controller to be its delegate.
When the registration is completed, the view tell the delegate to remove its child controller.
#pragma mark - RegViewDelegate
-(void)parentViewControllerPop{
[_cRegController removeFromParentViewController];
NSLog(#"_cRegController removed from parent viewcontroller");
}
However, after that, the view is still showing on the screen, why?
I don't think what the design is a good one, but I don't know what is the best way to implement what I want.
Can anyone help?
To remove a child view controller from his parent you need to do this 3 steps:
viewController.willMoveToParentViewController(nil)
viewController.view.removeFromSuperview()
viewController.removeFromParentViewController()
Reference: Removing a Child View Controller.

ViewController not release when come back from segue

I am using swift to perform segue programatically. First, I created a segue between two controllers in storyboard. Below is the code to show a view controller:
self.performSegueWithIdentifier("EditImage", sender: imageSampleBuffer)
When executing the above code, a new controller view will be presented on the UI. Then I click the "back" button on the top-left corner. The ui will come back to the previous view. It works fine here. But when I profile my app with instrument I found that the controller(pointed by "EditImage" segue) not released. When I click the controller instance on instrument, it shows that the above code is referencing this controller instance. When I perform these two controller back and forth, the instance number of that controller keep increasing. I didn't create any action function for the "back" button. All uses the default logic with navigation controller. So how to release controller when come back? Should I write any code on go back action?
In the UIViewController that is not been release add a deinit method and place add a breakpoint there, you will find if there is any other object keeping that reference form outside. Any public var could keep that reference, that's why all delegates should has weak reference. example
I did find a reference problem in my code. I cleared that reference in viewDidDisappear() method then it works fine. But I don't understand why instrument didn't give me the correct place where is holding my controller instance.

Specifying a Delegate before ViewDidLoad in Tabs

So, I followed this tutorial: http://enroyed.com/ios/how-to-pass-data-between-ios-tab-bars-using-delegate/
And the most important part of the tutorial:
- (void)viewDidLoad
{
[super viewDidLoad];
SecondViewController *svc = [self.tabBarController.viewControllers objectAtIndex:1];
svc.delegate = self; //important !! otherwise delegation will not work !
}
The problem is that even if I put it in "viewWillLoad", it still forces me to click on my tab before it initializes. How can I specify this before I click on the tab?
Edit
I have a three tab project. I used that tutorial in the link pass data from tab 1 to tab 2. The data passed is a url from a webview on tab 1 to a url on tab 2. The url gets pass when I click a link on the 1st tab.
The data does get passed, but only if I physically click on the 2nd tab first and then click back to the 1st and click on the link.
So, it appears to me that my code above only runs if I physically click on the 2nd tab.
Your problem is that - until you actually go to tab item 2, secondViewController is not fully initialised, and so there is no data to transfer from vc2 to vc1. In particular, secondViewController's view has not yet loaded, so there is no value to be had from it's slider yet, and no slider, so also no IBAction method to call to trigger the delegate method. Indeed, as the data transfer is only triggered on moving the slider in VC2, it should be fairly obvious that until you go to vc2 and move the slider, nothing is going to happen.
The example you link to uses the delegation pattern, which seems a fairly poor way to deal with your problem. The delegation pattern most comfortably fits with the scenario where there is a hierarchical relationship between delegator (owned) and delegatee (owner) ... not always, but most commonly. In a tab bar controller, the relationships are more like kindred child relationships to the tab bar controller itself.
You haven't offered enough detail in your question as to what you want to achieve, but you need to consider this:
When a tabBarController loads, all of it's child viewControllers are initialised but their views are not loaded.
This means that these methods do get called:
//if loading from a xib or in code
- (id) initWithNibName:bundle
//if loading from a storyboard
- (id) initWithCoder:
- (void) awakeFromNib
But the view loading methods (viewDidLoad, viewWillAppear etc) do not get called as the view does not get loaded unless you actually open the relevant tab.
You could solve this by putting an initialised variable into your viewController2 (in one of the init methods) and accessing that variable via property syntax from vc1. But then, you might as well just put an initialised value directly into vc1. You need to think closely about how each vc is dependent on the other, how you can decouple that dependency, and perhaps how to set up an independent data source that both vcs can access as needed. This could be a model class, or NSUserDefaults, or a property in your appDelegate... just a few of the many possible solutions.

Resources