【发布时间】:2015-04-07 12:40:42
【问题描述】:
我正在尝试投射我自己的自定义单元格,但似乎无法正常工作,我是 IOS 和 swift dev 的新手...从教程中我正在观看它工作正常,但是当我尝试时,它给了我一个错误.
这是代码。
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”
【问题讨论】:
-
是编译时错误还是运行时错误?
标签: ios uitableview swift xcode6