在viewControl中,加入-(void)prepareForSegue:(UIStoryBoardSegue *)segue sender: (id)sender方法,會在通過segue跳轉之前執行。
-(void)prepareForSegue:(UIStoryBoardSegue *)segue sender: (id)sender{
id destController=segue.destinationViewController;//獲取segue將要跳轉到的目標視圖控制器
destController setValue:self.label.text forKey:@"XXX"];//通過KVC方式將label內的文本設爲destController的XXX的屬性值
}
For example, if the segue originated from a table view, the sender parameter would identify the table view cell that the user tapped. You could use that information to set the data on the destination view controller.
當你點擊一個表格單元格進行segue跳轉,調用prepareForSegue方法時,sender參數就是你點擊的那個表格單元格,你可以用這個信息來設置目標VC的數據。
UIStoryBoardSegue有三個property,destinationViewController,sourceViewController,identifier.當一個viewController有多個segue並且要調用prepareForSegue時,通過identifier進行區分segue。
if you have a source view controller that can segue to two or more different
destination view controllers, you would assign different identifiers to each segue so that the source view controller’s prepareForSegue:sender:
method
could tell them apart and prepare each segue appropriately.