gpt4 book ai didi

ios - UiTabController 应用程序设置

转载 作者:行者123 更新时间:2023-11-30 11:48:21 25 4
gpt4 key购买 nike

我正处于项目的开始阶段。它是一个带有三个选项卡的 UITabbedApplication。 [0] 位置的选项卡是“位置选择器”,[1] 选项卡是位置选择器 View 中选取的位置的“查看配置文件”。根据首先选择的位置,我希望“查看配置文件”选项卡显示该特定位置的配置文件。我可以使用容器 View 来执行此操作吗?或者我想要的设置方式是否行不通?任何建议都会有帮助。

 //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)
}

}

最佳答案

我的 Storyboard:

A tab Bar Controller - > 

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

enter image description here

我的结构类将从 VC2 获取数据到 VC3

struct Global
{
static var Location : String!
}

我的 VC2 类(class):

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 类(class):

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.
}
}

关于ios - UiTabController 应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48575507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com