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

标签 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 单元格提供的删除按钮后。

我猜我需要修改 friend ,profileImages 字符串数组?我在哪里可以做到这一点而不会崩溃?或者是否有我应该使用的委托(delegate)方法?

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

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'

最佳答案

您发送的是 NSNumber(行)而不是 IndexPath 数组,后者是该方法的第一个参数。

你想要:

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

关于ios - '-[__NSCFNumber 行] : unrecognized selector sent to instance 0xb416910',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24688210/

相关文章:

iphone - 通过 UIView 更改 MaskedLayer 的大小

ios - 这个错误怎么可能 : Unrecognized Selected (screenFontWithRenderingMode) in iOS?

ios - UISearchBar 出现在 UITableView 的*底部*

ios - 没有动画的deleteRowsAtIndexPaths

iphone - UIPickerView 如何处理 2 个以上的转盘旋转?

iphone - 是否可以从 Nib 的代码中访问 UITableView 的 ScrollView?

ios - 有没有一种干净的方法来执行 segue 和 "forget"最后一个 ViewController?

ios - 当应用程序进入后台时如何停止更新位置(ios 6)

ios - UiCollectionView 必须使用非 nil 布局参数初始化 Swift 3

ios - Swift 3 - 连接到 MySql