[英]'(String) -> AnyObject?' is not convertible to 'ResultCell'
我正在尝试投射自己的自定义单元,但似乎无法正常工作,我是IOS和Swift开发的新手。从教程中,我看到它工作正常,但是当我尝试时,它给了我一个错误。
这是代码。
class UsersViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var resultTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
let height = view.frame.height
let width = view.frame.width
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 120
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell : ResultCell = UITableView.dequeueReusableCellWithIdentifier("userCell") as ResultCell
return cell
}
func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
}
// Deactivate the return button
override func viewWillAppear(animated: Bool) {
self.navigationItem.hidesBackButton = true
}
}
这是我创建的单元格
class ResultCell: UITableViewCell {
@IBOutlet weak var ContactprofilePic: UIImageView!
@IBOutlet weak var contactUserName: UILabel!
@IBOutlet weak var contactStatus: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let aWidth = UIScreen.mainScreen().bounds.width
contentView.frame = CGRectMake(0, 0, aWidth, 120)
ContactprofilePic.center = CGPointMake(60, 60)
ContactprofilePic.layer.cornerRadius = ContactprofilePic.frame.size.width/2
ContactprofilePic.clipsToBounds = true
contactUserName.center = CGPointMake(230, 55)
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
但是然后我得到这个错误
(字符串)-> AnyObject?' 不能转换为'ResultCell'
UITableView.dequeueReusableCellWithIdentifier(...)
应该
tableView.dequeueReusableCellWithIdentifier(...)
dequeueReusableCellWithIdentifier()
是一个实例方法,必须在tableView
实例上调用,该实例作为第一个参数传递到cellForRowAtIndexPath
方法。
其实表达
UITableView.dequeueReusableCellWithIdentifier
有效 ,如http://oleb.net/blog/2014/07/swift-instance-methods-curried-functions/中所述 。 该表达式的值是该类型的“咖喱函数”
(UITableView) -> (String) -> AnyObject?
这很可能不是您打算执行的操作,但是说明了错误消息
(String) -> AnyObject?' is not convertible to 'ResultCell'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.