I have set up a collection view that presents different view controllers on cell click in a container below the collection view. These different view controllers are consisted of page views that present different number of products from the same category which is selected in the collection view.
I want to add a button to the pages such that every page should present detailed information about that product (ex. popping in another view controller) on touch up inside. I can't come up with anything by now and I'll be really grateful if somebody shows me how to do that.
Thanks in advance.
This is the collection view, which cells are presented in the container.
This is the view controller that is presented in the container.
Here is the code for my first product page view:
var pageViewController: UIPageViewController!
var pageTitles:NSArray!
var pageImages:NSArray!
var productTitle:NSArray!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.pageTitles = NSArray(objects: "За още по-ефективна подкрепа на вените.", "Живей с лекота без разширени вени.", "За ефективна подкрепа на вените.", "Единствените в България кърпички против хемороиди.")
self.pageImages = NSArray(objects: "RuvenorForte.jpg", "RuvenorGel.jpg", "RuvenorKapsuli.jpg", "RuvenorKurpi.jpg", "ProbienFemiFlora.jpg")
self.productTitle = NSArray(objects: "Рувенор Форте", "Рувенор гел", "Рувенор капсули","Рувенор кърпи")
self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageViewController") as! UIPageViewController
self.pageViewController.dataSource = self
let startVC = self.viewControllerAtIndex(0) as ContentViewController
let viewControllers = NSArray(object: startVC)
self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: .Forward, animated: true, completion: nil)
//self.pageViewController.view.frame = CGRectMake(0, 62, self.view.frame.width, self.view.frame.size.height - 60)
let height = UIScreen.mainScreen().bounds.size.height
if height == 568 {
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height - 66) }
else if height == 667{
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height - 66)
}
else {
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height - 230) }
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
}
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func viewControllerAtIndex(index: Int) -> ContentViewController
{
if ((self.pageTitles.count == 0) || (index >= self.pageTitles.count)) {
return ContentViewController()
}
let vc: ContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ContentViewController") as! ContentViewController
vc.imageFile = self.pageImages[index] as! String
vc.titleText = self.pageTitles[index] as! String
vc.product = self.productTitle[index] as! String
vc.pageIndex = index
return vc
}
// MARK: - Page View Controller Data Source
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
{
let vc = viewController as! ContentViewController
var index = vc.pageIndex as Int
if (index == 0 || index == NSNotFound)
{
return nil
}
index--
return self.viewControllerAtIndex(index)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let vc = viewController as! ContentViewController
var index = vc.pageIndex as Int
if (index == NSNotFound)
{
return nil
}
index++
if (index == self.pageTitles.count)
{
return nil
}
return self.viewControllerAtIndex(index)
}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int
{
return self.pageTitles.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int
{
return 0
}}
And this is the code from the view controller to whom I pass all the information:
class ContentViewController: UIViewController {
#IBOutlet weak var imageView: UIImageView!
#IBOutlet weak var titleLabel: UILabel!
#IBOutlet var lightPurpleView: UIView!
#IBOutlet var productTitle: UILabel!
#IBOutlet var infoLabel: UILabel!
#IBOutlet var scrollView: UIScrollView!
#IBOutlet var infoTextField: UITextView!
#IBOutlet var infoTextField1: UITextView!
#IBOutlet var infoTextField2: UITextView!
var pageIndex: Int!
var titleText: String!
var imageFile: String!
var infoButton: UIButton!
var product: String!
var listovka: String!
var listovka1: String!
var listovka2: String!
override func viewDidLoad()
{
super.viewDidLoad()
let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
upSwipe.direction = .Up
view.addGestureRecognizer(upSwipe)
imageView.addGestureRecognizer(upSwipe)
self.imageView.image = UIImage(named: self.imageFile)
self.titleLabel.text = self.titleText
self.infoTextField.text = self.listovka
self.infoTextField1.text = self.listovka1
self.infoTextField2.text = self.listovka2
self.productTitle.text = self.product
self.lightPurpleView.layer.cornerRadius = 10
imageView.layer.cornerRadius = 10
imageView.clipsToBounds = true
self.infoLabel.text = "Листовка"
scrollView.contentSize.height = 3375
scrollView.layer.cornerRadius = 10
self.infoTextField.layer.cornerRadius = 10
self.infoTextField.clipsToBounds = true
self.infoTextField1.layer.cornerRadius = 10
self.infoTextField1.clipsToBounds = true
self.infoTextField2.layer.cornerRadius = 10
self.infoTextField2.clipsToBounds = true
self.scrollView.showsVerticalScrollIndicator = false
lightPurpleView.layer.shadowColor = UIColor.darkGrayColor().CGColor
lightPurpleView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
lightPurpleView.layer.shadowOpacity = 1.0
lightPurpleView.layer.shadowRadius = 2
lightPurpleView.layer.masksToBounds = true
lightPurpleView.clipsToBounds = false
imageView.layer.shadowColor = UIColor.darkGrayColor().CGColor
imageView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
imageView.layer.shadowOpacity = 1.0
imageView.layer.shadowRadius = 2
imageView.layer.masksToBounds = true
imageView.clipsToBounds = false
}}
So basically I want to add this button, which is on the second picture and instead of scrolling down to see the textViews, just to present them in another view controller (dependent on the indexPath of the page view for that product category) that pops up.
Related
I have a viewcontroller that has a tableview and a button at the bottom. Within each cell is a radio button as a tapGesture. I would like to updated the button with the number of cells selected. If my gesture is in the custom cell and my button is in my viewcontroller how can I get the two to work together?
Custom cell:
class SearchTalentCell: UITableViewCell {
#IBOutlet weak var userProfileImage: UIImageView!
#IBOutlet weak var talentUserName: UILabel!
#IBOutlet weak var selectedImg: UIImageView!
#IBOutlet weak var inviteSentImg: UIImageView!
var prospectRef: FIRDatabaseReference!
var currentTalent: UserType!
func setTalent(talent: UserType) {
currentTalent = talent
currentTalent.userKey = talent.userKey
}
override func awakeFromNib() {
super.awakeFromNib()
let tap = UITapGestureRecognizer(target: self, action: #selector(selectTapped))
tap.numberOfTapsRequired = 1
selectedImg.addGestureRecognizer(tap)
selectedImg.isUserInteractionEnabled = true
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func configureCell(user: UserType, img: UIImage? = nil) {
prospectRef = Cast.REF_PRE_PRODUCTION_CASTING_POSITION.child(ProjectDetailVC.currentProject).child(FIRDataCast.prospect.rawValue).child(CastingDetailVC.positionName).child(user.userKey)
setTalent(talent: user)
self.talentUserName.text = "\(user.firstName) \(user.lastName)"
prospectRef.observeSingleEvent(of: .value, with: { (snapshot) in
if let _ = snapshot.value as? NSNull {
self.inviteSentImg.isHidden = true
} else {
self.inviteSentImg.image = UIImage(named: "inviteSent")
self.inviteSentImg.isHidden = false
}
})
if UserType.selectedTalentForSearch.contains(currentTalent.userKey) {
selectedImg.image = UIImage(named: "radioSelected")
} else {
selectedImg.image = UIImage(named: "radioUnselected")
}
//Image Caching
if img != nil {
self.userProfileImage.image = img
} else {
if let imageURL = user.profileImage {
let ref = FIRStorage.storage().reference(forURL: imageURL)
ref.data(withMaxSize: 2 * 1024 * 1024, completion: { (data, error) in
if error != nil {
print("ZACK: Unable to download image from Firebase Storage")
} else {
print("ZACK: Image downloaded from Firebase Storage")
if let imgData = data {
if let img = UIImage(data: imgData) {
self.userProfileImage.image = img
SearchTalentVC.userProfileImageCache.setObject(img, forKey: imageURL as NSString)
}
}
}
})
}
}
}
#objc func selectTapped(sender: UITapGestureRecognizer) {
if UserType.selectedTalentForSearch.contains(currentTalent.userKey) {
selectedImg.image = UIImage(named: "radioUnselected")
UserType.selectedTalentForSearch = UserType.selectedTalentForSearch.filter{$0 != currentTalent.userKey}
print("Keys: \(UserType.selectedTalentForSearch)")
} else {
selectedImg.image = UIImage(named: "radioSelected")
UserType.selectedTalentForSearch.append(currentTalent.userKey)
print("Keys: \(UserType.selectedTalentForSearch)")
}
}
}
ViewController:
class SearchTalentVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var sendInviteButton: UIButton!
var searchingRole = [Cast]()
var unfilteredTalent = [UserType]()
var filteredTalent = [UserType]()
var selectedTalent = [UserType]()
var matchingTalentUserKeys = [String]()
var isFiltered = false
var selectedCounter = [String]()
var prospectRef: FIRDatabaseReference!
static var userProfileImageCache: NSCache<NSString, UIImage> = NSCache()
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Talent"
searchController.searchBar.barStyle = .black
navigationItem.searchController = searchController
definesPresentationContext = true
searchController.searchBar.scopeButtonTitles = ["All", "Role Specific"]
searchController.searchBar.tintColor = UIColor.white
searchController.searchBar.delegate = self
searchController.searchResultsUpdater = self
self.sendInviteButton.setTitle("Send Invite to \(UserType.selectedTalentForSearch.count) Prospects", for: .normal)
getTalentProfiles()
}
Thank you for any help!
I'm not sure why you are using the cell selection inside the cell, as opposed to the tableview delegate function func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)?
If you use didSelectRowAt, you could have an array of selected rows and you can include the selectedRows.count into your button text.
Hope that helps!
I am loading a views from nib and i am successfully loaded but first one is loaded perfect but in second view getting nil outlets. below is my code.
Set a global variable to loadview by default is is 0 and it is increase when i press next button.
User is struct here :
struct User {
static var quizIndexNo = 0
}
This method is in my ViewController
let moptViewInstance = MOPT()
let rmkViewInstance = RMK()
getting view name from this array:
let viewName = ["MOPT","RMK"]
func loadQuizView(){
if viewName[User.quizIndexNo] == "MOPT" {
for views in vwOptionView.subviews {
views.removeFromSuperview()
}
moptViewInstance.prepareScreenWithView(navigationController: UINavigationController(), viewSize: self.vwOptionView, viewController: self)
} else if viewName[User.quizIndexNo] == "RMK" {
for views in vwOptionView.subviews {
views.removeFromSuperview()
}
rmkViewInstance.prepareScreenWithView(navigationController: UINavigationController(), viewSize: self.vwOptionView, viewController: self)
}
}
// NIB View Classes
class MOPT: UIView {
#IBOutlet weak var btnPrevious: UIButton!
#IBOutlet weak var btnNext: UIButton!
var nibView: UIView!
var instanceOfQuizController : QuizCointroller!
func prepareScreenWithView(navigationController: UINavigationController, viewSize: UIView, viewController: UIViewController) {
nibView = Bundle.main.loadNibNamed("MOPT", owner: self, options: nil)?[0] as! UIView
nibView.tag = 200
var tempRect = nibView.frame
print(tempRect)
if User.quizIndexNo == 0 {
btnPrevious.isHidden = true
}
if User.quizIndexNo == 0 {
btnNext.setTitle("Test", for: .normal)
}
print("Index No is: \(User.quizIndexNo) and \(Sequence.totalQuizQuestionCout)")
if User.quizIndexNo == Sequence.totalQuizQuestionCout - 1 {
btnNext.setTitle("Submit", for: .normal)
}
instanceOfQuizController = viewController as! QuizCointroller
tempRect = CGRect(x: 0, y: 0, width: viewSize.bounds.width, height: viewSize.bounds.height)
viewSize.addSubview(self.nibView)
self.nibView.frame = tempRect
}
#IBAction func btnPrev(_ sender: UIButton) {
User.quizIndexNo -= 1
Sequence.instanceOfQuizControllerTest.previousButtonPressed()
}
// Next button will reload next view
#IBAction func btnNext(_ sender: UIButton) {
User.quizIndexNo += 1
// here sequence is global variable of type ViewController
Sequence.instanceOfQuizControllerTest.nextButtonPressed()
}
}
Second NibView Class
class RMK: UIView {
#IBOutlet weak var btnPrevious: UIButton!
#IBOutlet weak var btnNext: UIButton!
var nibView: UIView!
var instanceOfQuizControllerTest : QuizCointroller!
func prepareScreenWithView(navigationController: UINavigationController, viewSize: UIView, viewController: UIViewController) {
nibView = Bundle.main.loadNibNamed("RMK", owner: self, options: nil)?[0] as! UIView
nibView.tag = 200
var tempRect = nibView.frame
print(tempRect)
if User.quizIndexNo == 1 {
btnPrevious.isHidden = true //app is crashing here when i am trying to set title Button is showing nil
}
if User.quizIndexNo == 1 {
btnNext.setTitle("Submit", for: .normal)
}
instanceOfQuizControllerTest = viewController as! QuizCointroller
print("Quiz ViewController instatnce \(instanceOfQuizControllerTest)")
tempRect = CGRect(x: 0, y: 0, width: viewSize.bounds.width, height: viewSize.bounds.height)
viewSize.addSubview(self.nibView)
self.nibView.frame = tempRect
}
#IBAction func btnPrev(_ sender: UIButton) {
User.quizIndexNo -= 1
Sequence.instanceOfQuizControllerTest.previousButtonPressed()
}
#IBAction func btnNext(_ sender: UIButton) {
print(instanceOfQuizControllerTest)
User.quizIndexNo += 1
Sequence.instanceOfQuizControllerTest.nextButtonPressed()
}
}
Hi am following a tutorial on UIPageViewController to generate a gallery of pictures in my project http://www.theappguruz.com/blog/easy-steps-to-implement-uipageviewcontroller-in-swift even download the demo and it works but in my if I get an error and the application falls.
fatal error: unexpectedly found nil while unwrapping an Optional value
at next my code.
PageContentViewController.swift:
import UIKit
class PageContentViewController: UIPageViewController {
#IBOutlet weak var lblTitle: UILabel!
#IBOutlet weak var imageView: UIImageView!
var pageIndex: Int = 0
var strTitle: String!
var strPhotoName: String!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = UIImage(named: strPhotoName)
lblTitle.text = strTitle
}
}
ViewController2.swift
import UIKit
class ViewController2: UIPageViewController, UIPageViewControllerDataSource
{
var arrPageTitle: NSArray = NSArray()
var arrPagePhoto: NSArray = NSArray()
override func viewDidLoad() {
super.viewDidLoad()
arrPageTitle = ["This is The App Guruz", "This is Table Tennis 3D", "This is Hide Secrets"];
arrPagePhoto = ["1.jpg", "2.jpg", "3.jpg"];
self.dataSource = self
self.setViewControllers([getViewControllerAtIndex(0)] as [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}
// MARK:- UIPageViewControllerDataSource Methods
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
{
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if ((index == 0) || (index == NSNotFound))
{
return nil
}
index -= 1;
return getViewControllerAtIndex(index)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?
{
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if (index == NSNotFound)
{
return nil;
}
index += 1;
if (index == arrPageTitle.count)
{
return nil;
}
return getViewControllerAtIndex(index)
}
// MARK:- Other Methods
func getViewControllerAtIndex(index: NSInteger) -> PageContentViewController
{
// Create a new view controller and pass suitable data.
let pageContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageContentViewController") as! PageContentViewController
pageContentViewController.strTitle = "\(arrPageTitle[index])"
pageContentViewController.strPhotoName = "\(arrPagePhoto[index])"
pageContentViewController.pageIndex = index
return pageContentViewController
}
}
I believe Joakin is right, you are forcing the unwrap of an optional value, you need to either initialize your values when you declare them or treat them as optionals and unwrap them as you need them.
Try this:
var strTitle: String?
var strPhotoName: String?
override func viewDidLoad() {
super.viewDidLoad()
if let photoName = strPhotoName {
imageView.image = UIImage(named: photoName)
}
if let title = strTitle {
lblTitle.text = title
}
}
Then, somewhere in your code you need to specify the name of the image (make sure the image exists in your project) and the name of the title. If you dont specify them, the updated lines of code will not get executed.
Read more about optional values here
var strPhotoName: String!
It is literally nil. You will need to assign it a image name.
Let's say your image is called cloudsImage.png
You would set your var strPhotoName like this in viewDidLoad if you want.
override func viewDidLoad() {
super.viewDidLoad()
strPhotoName = "cloudsImage.png"
imageView.image = UIImage(named: strPhotoName)
lblTitle.text = strTitle
}
import UIKit
class PageContentViewController: UIViewController {
#IBOutlet weak var lblTitle: UILabel!
#IBOutlet weak var imageView: UIImageView!
var pageIndex: Int = 0
var strTitle: String!
var strPhotoName: String!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = UIImage(named: strPhotoName)
lblTitle.text = strTitle
}
}
the main error was that the class of the page was wrong now the problem is solved.
I just created a UIPageViewController with page content view controller that consists of single ImageView and a Button. It works almost flawlessly, but it has a major issue when I try to slide through the views in vertical view only, with Aspect Fill mode set for my ImageView (which is pretty much basically setup for this).
You can see this behavior right here: https://youtu.be/2yl6UXbUGQg
I am using autolayout, Button constraints are aligned to ImageView (full size), ImageView constraints are set to Superview...
Code:
1) UIPageViewController:
class ViewController: UIPageViewController, UIPageViewControllerDataSource {
var arrPageTitle: NSArray = NSArray()
var arrPagePhoto: NSArray = NSArray()
override func viewDidLoad() {
super.viewDidLoad()
arrPageTitle = ["page 1", "page 2", "page 3"]
arrPagePhoto = ["slider-1.jpg", "slider-2.jpg", "slider-3.jpeg"]
self.dataSource = self
self.setViewControllers([getViewControllerAtIndex(0)] as [UIViewController],
direction: .Forward,
animated: false,
completion: nil)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if ((index==0) || (index == NSNotFound)) {
return nil
}
index -= 1
return getViewControllerAtIndex(index)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let pageContent: PageContentViewController = viewController as! PageContentViewController
var index = pageContent.pageIndex
if index == NSNotFound {
return nil
}
index += 1
if index == arrPageTitle.count {
return nil
}
return getViewControllerAtIndex(index)
}
func getViewControllerAtIndex(index: NSInteger) -> PageContentViewController {
let pageContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PageContentViewController") as! PageContentViewController
pageContentViewController.strTitle = "\(arrPageTitle[index])"
pageContentViewController.strPhotoName = "\(arrPagePhoto[index])"
pageContentViewController.pageIndex = index
return pageContentViewController
}
}
2) Content view controller, UIViewController:
class PageContentViewController: UIViewController {
#IBOutlet weak var imageView: UIImageView!
#IBOutlet weak var labelTitle: UIButton!
var pageIndex: Int = 0
var strTitle: String!
var strPhotoName: String!
override func viewDidLoad() {
super.viewDidLoad()
self.imageView.image = UIImage(named: self.strPhotoName)
self.labelTitle.setTitle(self.strTitle, forState: .Normal)
}
}
Your image views from one view controller are spilling over to other view controllers because you need to set clipsToBounds to true on your image views. This will prevent the contents of the image view from going beyond the image view's bounds.
Check Clip Subviews to prevent image view size stretched.
I m trying to design one screen which contain swipe part. I have one screen with one imageview and at the bottom there are two buttons. I want to swipe only the imageview not the bottom area. Screen is like this
At the moment the problem it is swiping the whole screen including buttons too.
Here is my code
ViewController.swift
import UIKit
class ViewController: UIViewController, UIPageViewControllerDataSource {
var pageImages:NSArray!
var pageViewController:UIPageViewController!
override func viewDidLoad() {
super.viewDidLoad()
pageImages = NSArray(objects: "startscreen1","startscreen2","startscreen3")
self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("MyPageViewController") as! UIPageViewController
self.pageViewController.dataSource = self
let initialContenViewController = self.pageTutorialAtIndex(0) as TutorialScreenViewController
let viewControllers = NSArray(object: initialContenViewController)
self.pageViewController.setViewControllers(viewControllers as! [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
/* self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)*/
self.pageViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height-100)
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func pageTutorialAtIndex(index: Int) -> TutorialScreenViewController
{
let pageContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("TutorialScreenViewController") as! TutorialScreenViewController
pageContentViewController.imageFileName = pageImages[index] as! String
pageContentViewController.pageIndex = index
return pageContentViewController
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
{
let viewController = viewController as! TutorialScreenViewController
var index = viewController.pageIndex as Int
if(index == 0 || index == NSNotFound)
{
return nil
}
index--
return self.pageTutorialAtIndex(index)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?
{
let viewController = viewController as! TutorialScreenViewController
var index = viewController.pageIndex as Int
if((index == NSNotFound))
{
return nil
}
index++
if(index == pageImages.count)
{
return nil
}
return self.pageTutorialAtIndex(index)
}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int
{
return pageImages.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int // The selected item reflected in the page indicator.
{
return 0
}
}
TutorialScreenViewController.swift
#IBOutlet weak var myImageView: UIImageView!
var imageFileName: String!
var pageIndex:Int!
var width:CGFloat!
#IBOutlet weak var loginButton: UIButton!
#IBOutlet weak var registerButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
myImageView.image = UIImage(named:imageFileName)
}
You can use view controller containment:
Create a standard view controller that has the the two buttons and "container" view. Just search for "container" in the object library on the right panel in Interface builder and then drag that onto your main view controller's scene:
Obviously, set up your constraints so that this container view is properly laid out with the buttons.
Now control-drag from the container view to your page view controller, and choose the "embed" segue.
You'll end up with a scene that looks like:
Now you can enjoy the page view controller functionality from within a standard view controller with other buttons.