【问题标题】:Delegate table cell to other tableview将表格单元格委托给其他表格视图
【发布时间】:2016-02-21 00:06:51
【问题描述】:

我正在从事的项目取决于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
    }

【问题讨论】:

    标签: ios swift uitableview delegates cell


    【解决方案1】:

    首先UITableViewDataSource方法numberOfSectionsInTableView必须返回一个不同于0的值。在你的情况下它应该是1。

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    

    如果这不起作用,请确保您在 IB 或 viewDidLoad 中正确设置数据源。

    【讨论】:

    • 好的。您是否检查过 dataSource 方法,例如numberOfSectionsInTableView 被调用并且单元格是否正确出列?您的表格视图显示的内容是什么?
    • 在AppDelegate文件/类AppDelegate中不显示和引用这一行:UIResponder, UIApplicationDelegate {
    • 好的,该错误表明您的网点可能存在问题。在我看来,您的代码中还有更多问题。查看有关带有​​自定义单元格的 UITableView 的本教程。 appcoda.com/expandable-table-view
    猜你喜欢
    • 2021-05-08
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    相关资源
    最近更新 更多