2016-10-24 7 views
1

私はstoryboradにテーブルを作成しました。しかし、私はコードからそれを初期化します。問題は次のとおりです。私はそれがセルを示していないコードからそれをinializeとき、私の細胞はstatycあるTableviewcontrollerはセルを表示しません

enter image description here

テーブルビューコントローラのため、この私のコード:

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

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

を逃しましたか?コントローラはストーリーボードで設計されているので、デフォルトの初期化子 'AutorizedProfileTableViewController()'は決してストーリーボードにオブジェクトを返しません。 – vadian

+0

セルメソッドcellForRowAtがありませんか?私の答えを確認してください。http://stackoverflow.com/questions/40205397/ios-swift3-tableview-simple-display-value/40206096#40206096 – Joe

答えて

0

は、あなたが `cellForRowAtIndexPath`を逃すに関する警告/エラーを取得しないでくださいのviewDidLoad

+0

いいえ、 'UITableViewController'は暗黙的にデリゲートとデータソースを設定します。 – vadian

+0

mmm、AutorizedProfileTableViewControllerではなく2番目のコードに追加 –

関連する問題