2016-10-24 93 views
1

我在storyborad中創建了表格。但我從代碼中解除了它。問題是:當我從代碼它不顯示細胞inialize它,我的細胞是statycTableviewcontroller不顯示單元格

enter image description here

這是我對的tableview控制器代碼:

class AutorizedProfileTableViewController: UITableViewController { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    tableView.backgroundView=UIImageView(image: #imageLiteral(resourceName: "bg_profile")) 
    //tableView.backgroundColor=UIColor(colorLiteralRed: 69/255, green: 69/255, blue: 69/255, alpha: 0.3) 
    tableView.tableFooterView=UIView() 
    tableView.reloadData() 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Table view data source 

override func numberOfSections(in tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 1 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return 7 
} 

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    if indexPath.row == 0{ 
     return 250 
    } 
    else{ 
     return 50 
    } 
} 

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    cell.backgroundColor=UIColor.clear 
} 

/* 
// MARK: - Navigation 

// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
} 
*/ 

}

這是我如何從代碼中刪除它:

if (UIApplication.shared.delegate as! AppDelegate).currentcookie[HTTPCookiePropertyKey.value] != nil{ 
      let menuTable=AutorizedProfileTableViewController().self 
      let size=UIScreen.main.bounds.size 
      menuTable.view.frame=CGRect(x: size.width-(size.width*3/4), y: 0, width: size.width*3/4, height: size.height) 
      profile.addSubview(menuTable.view) 
     }else{ 
      let menuTable=NoAutorizedProfileTableViewController() 
      let size=UIScreen.main.bounds.size 
      menuTable.view.frame=CGRect(x: size.width-(size.width*3/4), y: 0, width: size.width*3/4, height: size.height) 
      profile.addSubview(menuTable.view) 
     } 
     self.navigationController?.view.addSubview(profile) 
     menuOpen=menuOpen ? false : true 
     if menuOpen{ 
      self.navigationController?.view.isUserInteractionEnabled=false 
      self.navigationController?.view.bringSubview(toFront: profile) 
     } 
     else{ 
      self.navigationController?.view.isUserInteractionEnabled=true 
      profile.removeFromSuperview() 
     } 

W帽子是問題,爲什麼我看不到我的細胞?

+1

下不要你會得到一個錯誤/警告失蹤'cellForRowAtIndexPath'?由於控制器是在故事板中設計的,故事板中的默認初始化器'AutorizedProfileTableViewController()'不會返回對象。 – vadian

+0

你想念你的cell方法cellForRowAt?檢查我的答案http://stackoverflow.com/questions/40205397/ios-swift3-tableview-simple-display-value/40206096#40206096 – Joe

回答

0

你錯過了

self.tableview.delegate = self 
self.tableview.datasource = self 

viewDidLoad中

+0

不,「UITableViewController」隱式設置委託和數據源。 – vadian

+0

mmm,不在AutorizedProfileTableViewController中,但將其添加到第二段代碼中 –