Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIPageViewController,每个页面上都有按钮,显示详细的视图控制器_Ios_Swift_Uipageviewcontroller - Fatal编程技术网

Ios UIPageViewController,每个页面上都有按钮,显示详细的视图控制器

Ios UIPageViewController,每个页面上都有按钮,显示详细的视图控制器,ios,swift,uipageviewcontroller,Ios,Swift,Uipageviewcontroller,我已经设置了一个集合视图,它在集合视图下方的容器中单击单元格时显示不同的视图控制器。这些不同的视图控制器由页面视图组成,这些页面视图表示在集合视图中选择的同一类别中不同数量的产品。 我想在页面上添加一个按钮,这样每个页面都应该在内部润色时显示关于该产品的详细信息(例如,在另一个视图控制器中弹出)。我现在想不出什么,如果有人教我怎么做我会非常感激的。 提前谢谢 这是集合视图,其中单元格显示在容器中 这是容器中显示的视图控制器 以下是我的第一个产品页面视图的代码: var pageViewCon

我已经设置了一个集合视图,它在集合视图下方的容器中单击单元格时显示不同的视图控制器。这些不同的视图控制器由页面视图组成,这些页面视图表示在集合视图中选择的同一类别中不同数量的产品。 我想在页面上添加一个按钮,这样每个页面都应该在内部润色时显示关于该产品的详细信息(例如,在另一个视图控制器中弹出)。我现在想不出什么,如果有人教我怎么做我会非常感激的。 提前谢谢

这是集合视图,其中单元格显示在容器中

这是容器中显示的视图控制器

以下是我的第一个产品页面视图的代码:

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
}}
这是来自视图控制器的代码,我将所有信息传递给它:

类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


}}

因此,基本上我想添加这个按钮,它位于第二张图片上,而不是向下滚动查看文本视图,只是在另一个视图控制器中显示它们(取决于该产品类别的页面视图的indexPath)弹出窗口。

到目前为止,您有什么代码/布局?添加按钮听起来很简单!?感谢您的回复。我进行了编辑。希望它能澄清我试图完成的工作。我看到的第一件事是您“手动”创建并添加了pageViewController,让界面生成器为您完成这项工作,您也可以在那里设置数据源和类似的内容。特别是,不要设置框架属性,让autolayout进行布局。谢谢,但即使我重新创建了页面视图控制器,如何添加此按钮并使其以正确的方式工作。