Ios 从ITableViewCell下载?要使用UITableViewCell,请仅打开选项
我如何解决这个问题?谢谢 这是一个tableviewcell错误,我不理解这个问题。请帮助我。 我有一个类似于ITableViewCell的Downcast的错误?要使UITableViewCell仅打开选项,是否要使用“!”Ios 从ITableViewCell下载?要使用UITableViewCell,请仅打开选项,ios,xcode,swift,tableview,Ios,Xcode,Swift,Tableview,我如何解决这个问题?谢谢 这是一个tableviewcell错误,我不理解这个问题。请帮助我。 我有一个类似于ITableViewCell的Downcast的错误?要使UITableViewCell仅打开选项,是否要使用“!” func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ var cell : UITableViewCe
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
var cell : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("cell") as?UITableViewCell
if(cell == nil)
{
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
}
let film = self.filmler[indexPath.row] as! Dictionary<String, AnyObject>
let filmAdi = film["ad"]! as! String
cell!.textLabel!.text = filmAdi
return cell!;
}
func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格{
变量单元格:UITableViewCell?=tableView.dequeueReusableCellWithIdentifier(“单元格”)作为?UITableViewCell
如果(单元格==nil)
{
单元格=UITableViewCell(样式:UITableViewCellStyle.Default,reuseIdentifier:“单元格”)
}
让film=self.filmler[indexPath.row]as!字典
让filmAdi=film[“ad”]!as!String
单元格!.textLabel!.text=filmAdi
返回单元!;
}
请在代码中添加此行
var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("cell")
dequeueReusableCellWithIdentifier返回可选类型UITableViewCell。所以你不需要输入cast
public func dequeueReusableCellWithIdentifier(identifier: String) -> UITableViewCell?
如果你像这样使用,那么它会工作。变量单元格:UITableViewCell?=tableView.dequeueReusableCellWithIdentifier(“单元”)作为?UITableViewCell在您的代码中,您没有维护任何sapce(作为?UITableViewCell),因此如果您维护空间(作为?UITableViewCell),则会显示错误,错误将被删除
public func dequeueReusableCellWithIdentifier(identifier: String) -> UITableViewCell?
var cell : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("cell")
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
}