-2

在我的第一个视图控制器中,我有分段控制。我正在尝试从我的第二个视图控制器获取分段控件的选定部分的标题的字符串值。任何人都知道如何做到这一点?提前致谢!

4

1 回答 1

0

您没有编写任何代码,但我认为这是一个存在和关闭的视图控制器场景,而不是addchildviewcontrolleror addsubview。在这种情况下,有很多方法可以做到这一点,这里有两种:

1)制作一个全局变量,检测分段控制的状态。

@IBOutlet weak var segContoll: UISegmentedControl!
func back() {
globalvar = segContoll.titleForSegment(at: segContoll.selectedSegmentIndex)
}

2)制定一个协议,它应该是这样的:

protocol NotifyDelegate {
    func collectionViewSelectedIndex(indexPath : Int)
}

class CollectionViewForSessions: ... {
    var delegate: NotifyDelegate?
func ... {
//The nextview delegate
    sessionCollection.delegate = self
}
    func ... {
//Instead of inputing a number, customize it to input a string segContoll.titleForSegment(at: segContoll.selectedSegmentIndex)
        delegate?.collectionViewSelectedIndex(indexPath: indexPath.row)
    }
}

class MessagesWithPerson: NotifyDelegate {
    func collectionViewSelectedIndex(indexPath: Int) {
    }
}
于 2017-06-14T16:21:28.537 回答