UiTabController 应用程序设置 [英] UiTabController app setup

查看:22
本文介绍了UiTabController 应用程序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am on the beginning stages of my project. It is a UITabbedApplication with three tabs. The tab at [0] position is the "Location picker", the [1] tab is the "view profiles" from the location picked in the Location picker view. Depending on the location that is first chosen I want the view profiles tab to show profiles from that specific location. Would I be able to do this with container views or is the way I want this set up not going to work? Any advice would be helpful.

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

}

推荐答案

My StoryBoard :

My StoryBoard :

A tab Bar Controller - > 

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

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

My Struct Class that Will take data from VC2 To 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.
    }
}

这篇关于UiTabController 应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆