【发布时间】:2018-07-31 03:02:57
【问题描述】:
我的视图控制器只需要传递一个名为“otherUser”的 NSDictionary。我正在使用分段控制器方便地向使用容器视图的用户呈现其中的 4 个视图。我知道所有这些视图将同时加载并保持加载状态,这就是我想要的,即使会占用内存。我知道如何直接将此值传递给视图控制器,但不知道如何将其传递给视图控制器,然后将其传播到 4 个视图以加载相同的数据。 ---- 下面是我根据搜索栏操作将“otherUser”传递给“BusinessProfileSwitchView”(带有容器视图的视图控制器)。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if segue.identifier == "BusinessProfiles" {
// gotta check if we're currently searching
if self.searchController.isActive && searchController.searchBar.text != "" {
if let indexPath = tableView.indexPathForSelectedRow {
let user = filteredUsers[indexPath.row]
let controller = segue.destination as? BusinessProfileSwitchView
controller?.otherUser = user
}
} else {
if let indexPath = tableView.indexPathForSelectedRow {
let user = usersArray[indexPath.row]
let controller = segue.destination as? BusinessProfileSwitchView
controller?.otherUser = user
}
}
}
}
你们认为我应该使用什么攻击方法将“otherUser”/NSDictionary 传递给带有容器视图的视图控制器,然后将“otherUser”传播到 4 个视图?下面是我连接到其他 4 个视图的视图控制器。
import UIKit
class BusinessProfileSwitchView: UIViewController {
@IBOutlet weak var feedView: UIView!
@IBOutlet weak var collectionView: UIView!
@IBOutlet weak var infoView: UIView!
@IBOutlet weak var socialView: UIView!
var infos: BusinessProfilesDetails!
var collections: BusinessProfilePostsCollection!
var feeds: BusinessProfilePostsFeed!
var socials: BusinessProfilesViewController!
@IBOutlet weak var switchController: UISegmentedControl!
var otherUser: NSDictionary!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
switch switchController.selectedSegmentIndex {
case 0:
infoView.isHidden = false
feedView.isHidden = true
collectionView.isHidden = true
socialView.isHidden = true
break
case 1:
infoView.isHidden = true
feedView.isHidden = true
collectionView.isHidden = false
socialView.isHidden = true
break
case 2:
infoView.isHidden = true
feedView.isHidden = false
collectionView.isHidden = true
socialView.isHidden = true
break
case 3:
infoView.isHidden = true
feedView.isHidden = true
collectionView.isHidden = true
socialView.isHidden = false
break
default:
break;
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func viewControl(_ sender: UISegmentedControl) {
switch switchController.selectedSegmentIndex {
case 0:
infoView.isHidden = false
feedView.isHidden = true
collectionView.isHidden = true
socialView.isHidden = true
break
case 1:
infoView.isHidden = true
feedView.isHidden = true
collectionView.isHidden = false
socialView.isHidden = true
break
case 2:
infoView.isHidden = true
feedView.isHidden = false
collectionView.isHidden = true
socialView.isHidden = true
break
case 3:
infoView.isHidden = true
feedView.isHidden = true
collectionView.isHidden = true
socialView.isHidden = false
break
default:
break;
}
}
}
【问题讨论】:
-
你在使用 4 个独立的容器视图吗?
-
是的,我正在使用 4 个视图
-
它们被标记为 feedView、collectionView、infoView 和 socialView。
-
好的 - 所以
infoView在你的故事板中设置为UIContainerView嵌入类似InfoViewViewController的东西?所以你需要访问InfoViewViewController的实例来设置它的otherUser属性?同样feedView/FeedViewViewController等等? -
是的,一个视图有 4 个容器,它们分成 4 个单独的视图,需要“otherUser”来执行 firebase 调用
标签: ios swift uisegmentedcontrol uicontainerview