我正处于我的项目的开始阶段。它是一个有三个选项卡的UITabbedApplication。位置处的选项卡是“位置选取器”,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)
}
}发布于 2018-02-02 13:03:39
我的StoryBoard:
A tab Bar Controller - >
-> VC2 tab[0]
-> VC3 tab[1]

我的将把数据从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.
}
}https://stackoverflow.com/questions/48575507
复制相似问题