简体   繁体   English

ImagesTabViewController'不符合协议'UITableViewDataSource'

[英]ImagesTabViewController' does not conform to protocol 'UITableViewDataSource'

I know this question has been asked a million times, but I can't find a resolution to this specific issue. 我知道这个问题已经被问了一百万遍了,但是我找不到针对这个特定问题的解决方案。 I'm using Xcode 6.3 beta 4 with Swift 1.2 and since the last update I haven't been able to get a regular UITableView with the supporting datasource and delegate protocols working. 我在Swift 1.2中使用了Xcode 6.3 beta 4,自上次更新以来,我一直无法使用支持数据源和委托协议的常规UITableView。

I am getting the above error and "Definition conflicts with previous value" for the numberOfRowsInSection function. 我收到上述错误,并且numberOfRowsInSection函数的“定义与先前的值冲突”。 At this point I don't know if it's a Swift change or I am missing something. 在这一点上,我不知道这是一个迅速的变化还是我错过了一些东西。 The tableview is connected properly.. tableview已正确连接。

Thanks for any help. 谢谢你的帮助。

class ImagesTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var collectionInfo: NSArray = DataManager.getUserCollections()

var items: NSMutableArray = []
var namesArray: NSMutableArray = []

override func viewDidLoad() {
    super.viewDidLoad()

    APIManager().getData() { completed in
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            if completed {

                self.collectionInfo = DataManager.getUserCollections()
                var collectionNames: AnyObject = self.collectionInfo[3]
                println(collectionNames)


                self.items = NSMutableArray(array: self.collectionInfo)
            } else {
                //do something else
            }
        })
    // Do any additional setup after loading the view.
}

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

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1
    }


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

        var collectionsAndArrays = PSCollection()
        let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")

        // Configure the cell...

        collectionsAndArrays = self.items[indexPath.row] as! PSCollection
        cell.textLabel!.text = collectionsAndArrays.name
        cell.detailTextLabel!.text = collectionsAndArrays.created_at

        return cell
    }


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        var numberOfCollections: Int = self.items.count

        return numberOfCollections

    }


}}

There is a bracket missing and didReceiveMemoryWarning must be overridden. 缺少括号,必须重写didReceiveMemoryWarning。 Here is the revised code: 这是修改后的代码:

class ImagesTabViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var collectionInfo: NSArray = DataManager.getUserCollections()

    var items: NSMutableArray = []
    var namesArray: NSMutableArray = []

    override func viewDidLoad() {
        super.viewDidLoad()

        APIManager().getData() { completed in
            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                if completed {
                    self.collectionInfo = DataManager.getUserCollections()
                    var collectionNames: AnyObject = self.collectionInfo[3]
                    println(collectionNames)
                    self.items = NSMutableArray(array: self.collectionInfo)
                } else {
                    //do something else
                }
            })
            // Do any additional setup after loading the view.
        }
    } // <- Was missing!

    // Override!
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

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


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var collectionsAndArrays = PSCollection()
        let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")

        // Configure the cell...

        collectionsAndArrays = self.items[indexPath.row] as! PSCollection
        cell.textLabel!.text = collectionsAndArrays.name
        cell.detailTextLabel!.text = collectionsAndArrays.created_at

        return cell
    }


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        var numberOfCollections: Int = self.items.count
        return numberOfCollections
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ViewController不符合协议UITableViewDataSource - ViewController does not conform to protocol UITableViewDataSource UITableView不符合协议UITableViewDataSource错误 - UITableView does not conform to protocol UITableViewDataSource error 类型TypeViewOne不符合协议UITableViewDataSource - type TypeViewOne does not conform to protocol UITableViewDataSource 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type “ViewController” does not conform to protocol 'UITableViewDataSource" 类型“ViewController”不符合协议“UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type'ViewController' does not conform to protocol 'UITableViewDataSource' 类型“ ViewController”不符合协议“ UITableViewDataSource” - Type 'ViewController' does not conform to protocol 'UITableViewDataSource' 我的UIViewController“不符合协议:&#39;UITableViewDataSource&#39;” - My UIViewController “does not conform to protocol: 'UITableViewDataSource'” 类型的viewcontroller不符合协议uitableviewdatasource - type viewcontroller does not conform to protocol uitableviewdatasource 错误:类型“ UserAccView”不符合协议“ UITableViewDataSource” - error : type “UserAccView” does not conform to protocol 'UITableViewDataSource'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM