Xcode 提供的重写方法未在Swift的UITableViewController类中编译
在swift中,如果我创建一个UITableViewController类型的新cocoa touch类,我将得到一个名为TableViewController.swift的文件:Xcode 提供的重写方法未在Swift的UITableViewController类中编译,xcode,swift,uitableview,cocoa-touch,uikit,Xcode,Swift,Uitableview,Cocoa Touch,Uikit,在swift中,如果我创建一个UITableViewController类型的新cocoa touch类,我将得到一个名为TableViewController.swift的文件: import UIKit class TableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() // Uncomment the follo
import UIKit
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 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.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 0
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 0
}
/*override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
return 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
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .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
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView!, moveRowAtIndexPath fromIndexPath: NSIndexPath!, toIndexPath: NSIndexPath!) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView!, canMoveRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
}
当我取消注释此提供的方法时:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell
// Configure the cell...
return cell
}
我遇到了这个编译器错误:“使用选择器'tableView:CellForRowatinex path'重写方法的类型不完整…”
我可以做些什么来解决这个问题,还是这只是一个测试版问题?tableView:DidSelectRowatineXcode 6 beta 6和Xcode 6 beta 7之间的方法声明已更改。此方法现在需要非可选参数,并返回非可选的
UITableViewCell
因此,对于Xcode 6 beta 7,您必须在UITableViewController
子类中设置以下行,以避免出现错误消息:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
...
}
而不是:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
...
}
有关更多详细信息,请参阅。您使用的是哪个版本的Xcode 6 beta?我使用Xcode 6 beta 7使用
覆盖func tableView(tableView:UITableView,CellForRowatineXpath indexPath:NSIndexPath)->UITableViewCell{
而不是覆盖func tableView(tableView:UITableView!CellForRowatineXpath indexPath:NSIndexPath!)->UITableViewCell!{
。