获取错误不明确地使用tableView(_:numberOfRowsInSection :) [英] Getting error Ambiguous use of tableView(_:numberOfRowsInSection:)

查看:1088
本文介绍了获取错误不明确地使用tableView(_:numberOfRowsInSection :)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xcode 7 beta而且我已经从教程中找到了这段代码但是我使用的是 UIViewController 而不是 UITableViewController 有很多原因。 (我不知道这是否导致了这个具体问题)。我已经得到 UIViewController 设置,就像典型的 UITableViewController 但是我遇到了错误

I am using xcode 7 beta and I have found this code off a tutorial however I am using a UIViewController instead of UITableViewController for many reasons. (I don't know if this is causing this specific issue). I have gotten the UIViewController setup just like a typical UITableViewController however I am running into the error


不明确地使用'tableView(_:numberOfRowsInSection:)

这是我的代码

class ShoppingViewController: UIViewController {
var toDoItems:NSMutableArray = NSMutableArray()

override func viewDidAppear(animated: Bool) {

    var userDefaults:NSUserDefaults = NSUserDefaults.standardUserDefaults()

    var itemListFromUserDefaults:NSMutableArray? = userDefaults.objectForKey("itemList") as? NSMutableArray

    if ((itemListFromUserDefaults) != nil){
            toDoItems = itemListFromUserDefaults!
    }

    **self**.tableView.reloadData()
}

以及

if (segue != nil && segue!.identifier == "showDetail") {
    var selectedIndexPath:NSIndexPath = **self**.tableView.indexPathForSelectedRow()
    var detailViewController:DetailsViewController = segue!.destinationViewController as! DetailsViewController
    detailViewController.toDoData = toDoItems.objectAtIndex(selectedIndexPath.row) as! NSDictionary

}

候选人(根据XCode):

Candidates (according to XCode):

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return toDoItems.count
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

    let toDoItem:NSDictionary = toDoItems.objectAtIndex(indexPath.row) as! NSDictionary
    cell.textLabel!.text = toDoItem.objectForKey("itemTitel") as? String

    return cell
}


推荐答案

升级到Xcode 7.1 beta后我遇到了类似的问题。我想知道这是否是测试中的错误?有没有人找到解决方案?

I've had a similar problem after upgrading to Xcode 7.1 beta. I wonder if this is a bug in the beta? has anyone found a solution?

UPDATE -
所以我在我的项目中解决了这个问题。我必须为我的tableView设置IBOutlet,然后在该对象上执行reloadData。例如将IBOutlet设置为myItemsTableView然后调用self.myItemsTableView.reloadData()并且工作正常。在这个项目中,它需要myItemsTableView并重新加载,而不是通用命令tableView.reloadData()。

UPDATE - so i solved this issue in my project. I had to set the IBOutlet for my tableView and then do the reloadData on that object. e.g. set IBOutlet to myItemsTableView then call self.myItemsTableView.reloadData() and that worked fine. On this project it needed myItemsTableView and reload on that rather than then generic command tableView.reloadData().

希望有所帮助。

这篇关于获取错误不明确地使用tableView(_:numberOfRowsInSection :)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆