Swift:TableviewController中的三个原型单元格将不会查看

问题描述:

我想在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

因为你总是想要的是3个细胞在你的表视图显示,你应该使用UITableView“静态单元格格式”风格。如果您选择适当的UITableView并查看属性检查器,则可以在故事板中进行设置。

然后,拖出正确数量的单元格并在故事板中对其进行配置。如果需要以编程方式操作它们或其内容,请将每个单元连接到IBOutlet

请注意,由于只允许在UITableViewController中使用静态表视图,因此您可能需要更改包含问题中包含的代码的类。

+0

谢谢,如果你可以删除你downvote :) – user3662992

+0

我的问题是downvoted从某人! – user3662992

+0

非常感谢你 – user3662992