我正在尝试使用 swift 为 iOS 8 制作一个应用程序。这里的目标是制作一种新闻提要。此提要显示用户的帖子,遵循特定模式。
我想到了使用 UITableView,其中每个单元格都遵循自定义布局。当我尝试访问其中的文本标签时出现问题。我尝试通过它的标签访问它,但是当我这样做时,整个应用程序崩溃了。报告的错误是 “Swift dynamic cast failed”
,我正在使用以下代码访问 View :
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cellId: String = "cell"
var cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellId) as UITableViewCell
if let ip = indexPath{
cell.textLabel.text = myData[ip.row] as String
var lbl = cell.contentView.viewWithTag(0) as UILabel
lbl.text = "ola"
}
return cell
}
我做错了什么吗?提前致谢!
最佳答案
我认为问题出在标记 0。所有 View 都使用默认值 0。因此请尝试另一个标记值。
关于ios - 通过 Swift 中的标签访问 UITableViewCell 内的不同 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25554364/