2017-03-18 58 views
0

我的Popover Controller彈出一個空白的TableView,我不知道爲什麼。我試圖改變單元格和視圖的顏色,當我單擊彈出窗口時,這似乎不會顯示出來。Popover tableview控制器沒有顯示Data Swift

這裏是啓動酥料餅代碼:

@IBAction func popOverButton(_ sender: UIButton) 
{ 

    let controller = TableViewController() 
    controller.modalPresentationStyle = .popover 
    // configure the Popover presentation controller 
    let popController: UIPopoverPresentationController? = controller.popoverPresentationController 
    popController?.permittedArrowDirections = [.down] 
    popController?.delegate = self 
    popController?.sourceView = sender 
    popController?.sourceRect = sender.bounds 
    popController?.backgroundColor = .white 
    self.parent?.present(controller, animated: true, completion: { }) 

} 

    func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle 
{ 
    return UIModalPresentationStyle.none 
} 

This Code Shows This

這是我爲我的泰伯維控制器代碼,我曾經嘗試過做一個普通視圖控制器把一個的tableview上的另一種方法但它產生了相同的結果。 進口的UIKit

class TableViewController: UITableViewController { 
var categories = PTTableView().titles 
//PTTableview.titles is a populated array from another viewcontroller  and it is not empty 
@IBOutlet var tableiViewOne: UITableView! 

override func viewDidLoad() 
{ 
    super.viewDidLoad() 
} 

override func numberOfSections(in tableView: UITableView) -> Int 
{ 
    return 0 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
      return categories.count 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
{ 


    let cell = tableiViewOne.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) as! PopOverTableViewCell 

    cell.cellLabelOne.text = categories[indexPath.row] 

    return cell 
} 

} 

而且是在故事板tableviewcontroller設置爲TableViewController。

更新: 我已經改變了部分的數量上tableviewcontroller 1,現在我的應用程序崩潰說致命錯誤:意外發現零而展開的可選值 (LLDB) 突出

let cell = tableiViewOne.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) as! PopOverTableViewCell 

故事板上的單元格名稱相同,並且設置爲相同的類別

回答

0

對於numberOfSections方法,您正在返回0。這將生成一個空表。

您至少應該有1個部分來顯示您的數據。所以你需要將它改爲return 1

+0

我這樣做,而現在它說意外地發現零而展開的可選值彰顯我讓電池= –

+0

你設置你的tableViewCell在你的故事板'PopOverTableViewCell'? –

+0

在故事板單元中的重用標識符中分配「myCell」 –

0

你是否設置了dataSource和delegate?

override func viewDidLoad() { 
    super.viewDidLoad() 
    tableView.dataSource = self 
    tableView.delegate = self 
}