How to add tableview controler inside pageview controler - ipad

I am implementing a tableview controller inside a pageview controller. For the first time it is loading properly, but when I try move on the previous / next page the view becomes Blank.
can any one suggest me how to load a tableview controller inside a pageview controller.
I am creating a form based application , so in a tableview there can be textfield, textview , imageview etc. Every thing works fine for first time only, next time only blank screen shows.
Please suggest me some solution.
Thanks.

Use Container view and then navigate to different view controller on page index changes

Related

How to automatically update a label on a viewcontroller from another viewcontroller while using a UIpageviewcontroller to navigate pages

I am currently using a UIPageviewcontroller to navigate between my 3 main viewcontrollers. I have a global variable that I set on the first page using a stepper. The value of that global variable is then used as the value for a label on the second page.
This works, but it requires a button on the 2nd page to update the label. The exception being when I first run the app and change the stepper on the first page before swiping to the second page - as I have the label being updated in the "override func viewdidload()"
I dont want to use a button to update my label on page 2. I would like to be able swipe to page 1, change the stepper, then when I swipe back to page 2, the label on page 2 is automatically updated. (repeatedly)
How do I do this?
Is there a way to kill view controllers within the UIpageviewcontroller? or is there a way to get the "override fun viewdidload()" function to run every time I swipe to a page?
The simple way to do this would be to update the label on page 2 in it's viewWillAppear method. That will get called each time you go back to your page 2 view controller.
Globals are not a great way to set up your data handling however.
You'd be better off making page 2's view controller the delegate on the first view controller. When the users changes the stepper on the first view controller, it could call a "valueChanged()` method on it's delegate.
You should read up on the delegate design pattern to figure out how to do this. It's VERY well documented, and is one of the most common patterns you will find in iOS development.

unwinding segue, need to refresh tableview

I have looked all over for this problem and I cannot find an answer.
So on the first page of my app I have a page in a navigation controller. Within that page is a tableview. Within the cells of the table, there is a button. For the view controller of the cells, I say remove the button from superview if user is not signed in. So when you first load the app, there is no button.
Now if you click the sign in button (a button at the top of the page), it goes to that page, then there's two possible things that can happen. At first what I was doing was making a segue back to the main page. Everything worked perfectly fine. The button appears in the cells.
But I don't like how a second copy of the main page is being added to the stack of navigation controllers. So what I have explored with now is the popnavigationcontroller method and the unwind segue. So they both work but the problem is when it unwinds back to the new page, the button I mentioned earlier does not appear in the cells, even though its supposed to appear since the user is signed in. The reason for this is because the method "dequeueReusuableCell" is using the old cells, in which I have removed the button. And now that the button is removed, there is no easy way for me to add it back in at the right place in the view.
So what is the best solution here? At first I was looking for a way to "clear" all the reusuablecells for a tableView but I'm not sure if I found an answer. What I would like to do is when I rewind back to that navigation controller, refresh everything like it was the first time ever seeing it.
I guess another solution I could do is to perform a normal segue from the sign in page to the main page, and then remove the previous redundant main navigation controller. Is there a better solution?
When your controller pops off the stack, the underlying view controller will have its viewDidAppear(animated:) function called. So you could have:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
tableView.reloadData()
}
This is assuming based on your post that the issue is only about reloading your table. If you reload the table and your cells are still not updating properly, you have an issue with your dataSource not configuring the cells properly. But I cannot tell if this is the case without any code.
Edit: this was a cell reuse issue. Cell configuation had some code to remove a subview in some instances, but never add the subview back if it was supposed to be there. The simplest fix is to use isHidden instead of outright removing the subview.

iOS Different Views for Table View Cell items

I just started iOS development last week and I am creating a Table View based application. I having trouble understanding how to use storyboard.
I want each Table Cell to open a different ViewController.
Currently it is setup like this:
Then in the Component View Controller I use if/else statements to determine what content to load. The problem occurs when one of the views needed a TabBar.
How do I assign different View Controllers to each individual cell, rather than one "template" view and forced to add everything dynamically.
First off, I will say that it probably isn't the best idea to assign an individual view per cell. However, if it is what you wish to do, then so be it.
What you would do is create a segue from the table view to the new view by clicking on the table view icon and dragging a segue like so:
2.You would give that segue an identifier like "embedTweetsSegue" or something.
You can then check for the cell being touched and perform the segue programmatically using:
performSegueWithIdentifier("embedTweetsSegue", sender: self)

Tableview moves down when pop back back to previous view controller

I m making an app of shopping cart using storyboard.when i move back from list of product ordered controller to list of order controller.order tableview moves down every time when i come back from product list.
Try this might help you.
Add the following to viewDidLoad.
self.automaticallyAdjustsScrollViewInsets = NO;
This solved my problem of table view moving down after navigating back to view controller.
See, carefully if label is placed inside tableviecell contentview, if it is not inside tableviewcell's contentview this problem comes out

Send data and Change Page on button press using UIPageControl

I am using UIPageControl and UIScrollView to move between the views by scrolling.
I have followed this tutorial.
I have a button in the first of the view controllers.
I would like to send data to the second view controller and also change the page. I would like to know how it is done.
You would need to have all of the view controllers created (born at least the first 2) rather than loading purely on demand (scroll).
Add a property to the first controller which holds a reference to the second controller. Set the reference when the instances are created.
When the button is tapped, use the reference to call a method on the second controller.

Resources