Sec*_*Son 1 uitableview ios swift xcode6
我正在尝试投射我自己的自定义单元格,但似乎没有工作,我是IOS的新手和快速开发...从教程我看它工作正常但是当我尝试时,它给了我一个错误.
这是代码.
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
}
}
Run Code Online (Sandbox Code Playgroud)
这是我创建的单元格
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
}
}
Run Code Online (Sandbox Code Playgroud)
但后来我收到了这个错误
(String) - > AnyObject?' 不能转换为'ResultCell'
UITableView.dequeueReusableCellWithIdentifier(...)
Run Code Online (Sandbox Code Playgroud)
应该
tableView.dequeueReusableCellWithIdentifier(...)
Run Code Online (Sandbox Code Playgroud)
dequeueReusableCellWithIdentifier()是一个实例方法,必须在tableView作为第一个参数传递给该cellForRowAtIndexPath方法的实例上调用.
实际上是表达方式
UITableView.dequeueReusableCellWithIdentifier
Run Code Online (Sandbox Code Playgroud)
是有效的,如http://oleb.net/blog/2014/07/swift-instance-methods-curried-functions/中所述.该表达式的值是该类型的"curried函数"
(UITableView) -> (String) -> AnyObject?
Run Code Online (Sandbox Code Playgroud)
这很可能不是您打算做的,但解释了错误消息
(String) -> AnyObject?' is not convertible to 'ResultCell'
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |