简体   繁体   中英

Getting error Ambiguous use of tableView(_:numberOfRowsInSection:)

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

Ambiguous use of 'tableView(_:numberOfRowsInSection:)

Here's my code

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()
}

as well as

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

}

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
}

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 - 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. eg 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().

hope that helps.

Make sure that you have initialized tableView properly. That fixed my same problem.

I had a similar issue that I resolved by naming my View Controller something else.

There must be a view controller in SDK named DetailsViewController or DetailViewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM