2017-04-14 31 views
1

我有我的UIViewController,這是一個人的個人資料頁面,它顯示他們的名字和圖片。在那UIViewController我有一個UIContainerView顯示一個靜態UITableView。我在加載配置文件頁面時更新表格單元格有點麻煩。這是我的故事板:更新容器視圖中的TableView

enter image description here

我曾嘗試以下,我UIViewController內。

我爲我的UIView創建了一個插座,並將人物對象傳遞給它。

在我的UIView中,我調用了segue將對象傳遞給UITableViewController,從那裏我將更新一些標籤。

func prepareForSegue(segue: UIStoryboardSegue!, sender: Any?){ 
    if segue.identifier == "containerSegue"{ 
     let statsTable = segue.destination as! CollectionTableViewController 
     statsTable.currentPerson = currentPerson 
    } 
} 

我的賽恩永遠不會被調用。我已經將它移到主要的UIViewController以防它應該從那裏被調用,但是不再被調用。我在做什麼這個方法錯了?

+0

並添加statsTable.tableView.reloadData()也。 –

+0

@DeepakKumar,segue永遠不會被要求傳遞的值通過? – Jonnny

+0

檢查我的答案在底部。 Segue方法永遠不會被調用,因爲tableviewcontroller被添加爲childviewcontroller –

回答

2

假設您已將Segue標識符設置爲「containerSegue」,那麼您的應該將其置於「統計」視圖控制器中。

你使用的是Swift 3嗎?這是可能的,你只是有FUNC定義錯誤:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "containerSegue" { 
     let statsTable = segue.destination as! CollectionTableViewController 
     statsTable.currentPerson = currentPerson 
    } 
} 

應該工作。

+0

是的,我使用Swift3,segue應該在我的UIView中,而不是我的UIViewController? – Jonnny

+0

它應該在ViewController類中...在你發佈的圖像中,我假設標記爲「Stats」的View Controller是類「StatsViewController.swift」(或類似的)。 – DonMag

+0

謝謝你,我用錯了方法。 womp womp! – Jonnny