我正在使用storyBoard處理Iphone應用程序。將自定義UITableViewCell的屬性傳遞給prepareForSegue方法中的目標視圖
我在UINavidationView中有一個UITableView。我在自定義單元格中加載數據。然後我當用戶點擊一個單元格時我轉到另一個視圖(ResultView)。
我在故事板中設置了視圖和segue。
我的目標是將數據從prepareForSegue方法傳遞給ResultView。
爲此,我創建了一個實現UITableViewCell的自定義單元。然後我添加了一個名爲creationDate的NSDate屬性。我需要將選定單元格的創建日期傳遞給ResultView。我有以下 ate = readingCell.creationDate;
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"resultViewSegue"])
{
//Get a reference to the destination
ResultsViewController * destinationView = segue.destinationViewController;
//I try to get the selected cell in order to pass it's property
historyCellClass * selectedCell = (historyCellClass*) sender;
//pass the creation date to the destination view (it has its own creation date property)
[destinationView setCreationDate:selectedCell.creationDate];
}
}
但是結果視圖的創建日期始終爲空。
看起來像我沒有得到所選單元格的參考以閱讀其屬性。
如何將單元格的日期傳遞給下一個視圖?
非常感謝您的幫助
我試過這個,但它在「didSelectRowAtIndexPath」之前進入「prepareForSegue」方法。任何想法爲什麼? – Youssef
對不起,我忘了提及這一點。我認爲這是一個真正的弱點 - 從細胞到下一個VC,它對我來說似乎非常玩具。將編輯答案... – danh
謝謝先生。它的工作就像一個魅力 – Youssef