gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 06:49:12 25 4
gpt4 key购买 nike

我正在实现一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com