首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UiTabController应用程序设置

UiTabController应用程序设置
EN

Stack Overflow用户
提问于 2018-02-02 12:00:18
回答 1查看 45关注 0票数 0

我正处于我的项目的开始阶段。它是一个有三个选项卡的UITabbedApplication。位置处的选项卡是“位置选取器”,1选项卡是在位置选取器视图中选择的位置的“视图配置文件”。根据首先选择的位置,我希望视图配置文件选项卡显示该特定位置的配置文件。我能用容器视图做到这一点吗?还是我想要的这种设置方式不起作用?任何建议都会有所帮助。

代码语言:javascript
复制
 //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)
}

}
EN

回答 1

Stack Overflow用户

发布于 2018-02-02 13:03:39

我的StoryBoard:

代码语言:javascript
复制
A tab Bar Controller - > 

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

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

代码语言:javascript
复制
struct Global
{
    static var Location : String!
}

我的VC2类:

代码语言:javascript
复制
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类:

代码语言:javascript
复制
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.
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48575507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档