UiTabController应用程序设置

时间:2018-02-02 04:00:18

标签: ios swift uitabbarcontroller

我正处于项目的开始阶段。它是一个带有三个选项卡的UITabbedApplication。 [0]位置的选项卡是"位置选择器",[1]选项卡是"视图配置文件"从位置选择器视图中选择的位置。根据首先选择的位置,我希望视图配置文件选项卡显示该特定位置的配置文件。我是否可以使用容器视图执行此操作,还是我希望此设置无法正常工作?任何建议都会有所帮助。

 //tab [0] choose location
 class ChooseLocationVC: UIViewController {
@IBAction func chooseAction(_ sender: Any) {
    if pageControl.currentPage == 0{

        print("LA")
    }
    else if pageControl.currentPage == 1{

        print("SF")
    }else if pageControl.currentPage == 2{

        print("NY")
    }else if pageControl.currentPage == 3{

        print("Miami")
    }else if pageControl.currentPage == 4{

        print("LasVegas")
    }else if pageControl.currentPage == 5{

        print("Chicago")
    }

}
@IBOutlet weak var collectionView: UICollectionView!
var thisWidth:CGFloat = 0

@IBOutlet weak var pageControl: UIPageControl!

var imageArray = [UIImage(named: "LA"),UIImage(named: "SF"), UIImage(named: "NY"), UIImage(named: "Miami"), UIImage(named: "LasVegas"), UIImage(named: "Chicago")]

override func viewDidLoad() {
    super.viewDidLoad()
    setLabels()
   // thisWidth = CGFloat(self.frame.width)
    collectionView.delegate = self
    collectionView.dataSource = self
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

       func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return imageArray.count
}

      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCollectionViewCell", for: indexPath) as! ImageCollectionViewCell
    cell.locationImage.image = imageArray[indexPath.row]
    return cell
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    pageControl.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
    setLabels()
    print(pageControl.currentPage)
}

}

1 个答案:

答案 0 :(得分:0)

My StoryBoard:

A tab Bar Controller - > 

  -> VC2 tab[0]
  -> VC3 tab[1]

enter image description here

将我的数据从VC2转移到VC3的结构类

struct Global
{
    static var Location : String!
}

我的VC2课程:

import UIKit

class VC2: UIViewController {

    @IBOutlet weak var textTF: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func viewWillAppear(_ animated: Bool)
    {
        print("Called of vC2")

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func saveValue(_ sender: Any)
    {
        Global.Location = self.textTF.text
    }

}

我的VC3课程:

import UIKit
class VC3: UIViewController {

    @IBOutlet weak var resultTf: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func viewWillAppear(_ animated: Bool) {
        print("Called of vC3")
        if Global.Location != ""
        {
            self.resultTf.text = Global.Location
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}