2015-07-12 48 views
2

我想在tableview控制器中創建三個單元格,並且在故事板中添加了三個原型單元格,但它不會崩潰,但會查看空的tableview。Swift:TableviewController中的三個原型單元格將不會查看

super.viewDidLoad() 

    // Uncomment the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem() 
    let nib1 = UINib(nibName: "one", bundle: nil) 
    tableView.registerNib(nib1, forCellReuseIdentifier: "one") 
    let nib2 = UINib(nibName: "two", bundle: nil) 
    tableView.registerNib(nib2, forCellReuseIdentifier: "two") 
    let nib3 = UINib(nibName: "three", bundle: nil) 

    tableView.registerNib(nib3, forCellReuseIdentifier: "three") 
} 

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

// MARK: - Table view data source 

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

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


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

//讓電池= tableView.dequeueReusableCellWithIdentifier( 「reuseIdentifier」,forIndexPath:indexPath) VAR細胞:UITableViewCell的!

switch (indexPath.row){ 
    case 0 : 
     cell = tableView.dequeueReusableCellWithIdentifier("one") as! one 
     cell.textLabel?.text = "book1" 
     break; 
    case 1: 
     cell = tableView.dequeueReusableCellWithIdentifier("two") as! two 
      cell.textLabel?.text = "book2" 
     break; 
    case 2 : 
     cell = tableView.dequeueReusableCellWithIdentifier("three") as! three 
      cell.textLabel?.text = "book3" 

    default: 
     break; 

    } 

    // Configure the cell... 

    return cell 
} 
+0

當您尋求幫助時,請務必提出明確的問題。 – ndmeiri

+0

抱歉什麼是不明確 – user3662992

+0

你的問題是什麼?你只說明瞭你的問題。 – ndmeiri

回答

1

因爲你總是想要的是3個細胞在你的表視圖顯示,你應該使用UITableView「靜態單元格格式」風格。如果您選擇適當的UITableView並查看屬性檢查器,則可以在故事板中進行設置。

然後,拖出正確數量的單元格並在故事板中對其進行配置。如果需要以編程方式操作它們或其內容,請將每個單元連接到IBOutlet

請注意,由於只允許在UITableViewController中使用靜態表視圖,因此您可能需要更改包含問題中包含的代碼的類。

+0

謝謝,如果你可以刪除你downvote :) – user3662992

+0

我的問題是downvoted從某人! – user3662992

+0

非常感謝你 – user3662992

相關問題