Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
}
like image 877
NewBeginnings Avatar asked Sep 27 '22 20:09

NewBeginnings


1 Answers

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

hope that helps.

like image 160
Ultronn Avatar answered Sep 30 '22 08:09

Ultronn