user3784622
user3784622

Reputation: 435

'-[__NSCFNumber row]: unrecognized selector sent to instance 0xb416910'

I am implementing a UITableViewController, it looks like the following:

import UIKit

class FriendsListTableViewController: UITableViewController, UITableViewDataSource, UITableViewDelegate {
    var friends = String[]()
    var profileImages = String[]()

    override func viewDidLoad() {
        super.viewDidLoad()
        friends = ["Joe Georgio", "Mafio Ambroso", "Tony Mozarotto", "Bob Jaymes", "Matthew Hall"]
        profileImages = ["logo60pt", "checkmark", "OrangeSplashScreen", "twittericon", "OrangeSplashScreen2"]

        // 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.
    }

    // #pragma mark - Table view data source

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

    override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return friends.count
    }


    override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
        let cell = tableView!.dequeueReusableCellWithIdentifier("FriendCell", forIndexPath: indexPath) as FriendTableViewCell

        cell.friendNameLabel.text = friends[indexPath!.row]
        cell.friendProfileImageView.image = UIImage(named: profileImages[indexPath!.row])

        return cell
        // Configure the cell...
    }


    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView?, canEditRowAtIndexPath indexPath: NSIndexPath?) -> Bool {
        // Return NO if you do not want the specified item to be editable.
        return true
    }
    */


    // Override to support editing the table view.
    override func tableView(tableView: UITableView?, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath?) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            //indexPath!.delete(indexPath!.row)
            tableView!.deleteRowsAtIndexPaths([indexPath!.row], withRowAnimation: UITableViewRowAnimation.Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }

It is crashing at the line that states:

tableView!.deleteRowsAtIndexPaths([indexPath!.row], withRowAnimation: UITableViewRowAnimation.Fade)

..after pressing the delete button provided by Apple for each TableView cell.

I am guessing I need to modify the friends, profileImages String arrays? Where can I do this without it crashing? Or is there a delegate method I am supposed to be using?

Edit: Here is the error message (without the call stack):

2014-07-10 20:04:56.404 TableViewController Test[3070:109022] -[__NSCFNumber row]: unrecognized selector sent to instance 0xb30a1b0 2014-07-10 20:04:56.408 TableViewController Test[3070:109022] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber row]: unrecognized selector sent to instance 0xb30a1b0'

Upvotes: 1

Views: 2161

Answers (1)

Jesse Naugher
Jesse Naugher

Reputation: 9820

You are sending an NSNumber (row) instead of an array of IndexPaths which is what that method takes as its first parameter.

you want:

tableView!.deleteRowsAtIndexPaths([indexPath!], withRowAnimation:UITableViewRowAnimation.None)

Upvotes: 3

Related Questions