' - [__ NSCFNumber行]:无法识别的选择器发送到实例0xb416910'

时间:2014-07-11 00:04:10

标签: ios cocoa-touch uitableview swift unrecognized-selector

我正在实现一个UITableViewController,它看起来如下:

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

它在崩溃的线上说明:

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

..按Apple为每个TableView单元格提供的删除按钮后。

我猜我需要修改朋友,profileImages字符串数组?我怎么能在没有崩溃的情况下做到这一点?或者是否有我应该使用的委托方法?

编辑:这是错误消息(没有调用堆栈):

  

2014-07-10 20:04:56.404 TableViewController测试[3070:109022]    - [__ NSCFNumber row]:发送到实例0xb30a1b0的无法识别的选择器2014-07-10 20:04:56.408 TableViewController测试[3070:109022] *   由于未捕获的异常而终止应用程序   'NSInvalidArgumentException',原因:' - [__ NSCFNumber行]:   无法识别的选择器发送到实例0xb30a1b0'

1 个答案:

答案 0 :(得分:3)

您正在发送NSNumber(行)而不是IndexPath的数组,这是该方法作为其第一个参数。

你想要:

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