我工作的项目依赖于UITableView。我在UIStoryboard中内置了六个主要类别。我希望每个单元格与另一个UITableView相关联。
我确实使用segue进行委托,但它不起作用。我需要在UITableView文件中委托一个方法:
class CategoriesView: UITableViewController {
@IBOutlet weak var OthersCell: UITableViewCell!
@IBOutlet weak var StoreCell: UITableViewCell!
@IBOutlet weak var ArtAndDesigneCell: UITableViewCell!
@IBOutlet weak var StudentServicesCell: UITableViewCell!
@IBOutlet weak var BeautyCell: UITableViewCell!
@IBOutlet weak var CheefsCell: UITableViewCell!
override func viewDidLoad() {
super.viewDidLoad()
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier=="CheefsCelll") {let _=segue.destinationViewController as! CheefsView}
else if (segue.identifier=="BeautyCell") {let _=segue.destinationViewController as! BeautyView}
else if (segue.identifier=="StudentServicesCell") {let _=segue.destinationViewController as! StudentServicesView}
else if (segue.identifier=="ArtAndDesigneCell") {let _=segue.destinationViewController as! ArtAndDesigneView}
else if (segue.identifier=="StoreCell") {let _=segue.destinationViewController as! StoreView}
else if (segue.identifier=="OthersCell") {let _=segue.destinationViewController as! OthersView}
}
// 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()
}
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 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 6
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.accessoryType=UITableViewCellAccessoryType.DisclosureIndicator
return cell
}发布于 2016-02-21 08:20:16
首先,UITableViewDataSource方法numberOfSectionsInTableView必须返回一个不同于0的值。在您的情况下,它应该是1。
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}如果这不起作用,请确保在IB或viewDidLoad中正确设置了dataSource。
https://stackoverflow.com/questions/35530652
复制相似问题