gpt4 book ai didi

ios - 在标签栏之间发送数据

转载 作者:行者123 更新时间:2023-11-28 13:01:55 25 4
gpt4 key购买 nike

我需要发送一条数据,指示哪一行将它从我的一个选项卡 tableviewcontroller 发送到主视图 Controller ,然后我可以根据 viewDidAppear 中的值采取行动

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

//selectedRow = indexPath.row
self.tabBarController?.selectedIndex = 0
}

然后在另一个 View Controller 中做一些事情:

override func viewDidAppear(animated: Bool) {
//selectedRow = row sent from tab bar,
//load data from plist at index of the selected row
}

最好的方法是什么?谢谢

最佳答案

您可以为其他 View Controller 声明属性并在 tableView:didSelectRowAtIndexPath: 方法中设置它的值。

其他 View Controller :

class OtherViewController: UIViewController {
var selectedRow: Int = 0

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
// load data from plist at index using selectedRow property
}
}

TableViewControllertableView:didSelectRowAtIndexPath::

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var tabIndex = 0

if let vc = self.tabBarController?.viewControllers?[tabIndex] as? OtherViewController {
vc.selectedRow = indexPath.row
}
self.tabBarController?.selectedIndex = tabIndex
}

关于ios - 在标签栏之间发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33647596/

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