Ios Swift-UITableView cell.detailTextLable.text不可见
我一直在尝试StackOverFlow中的所有方法以使其工作,但我没有运气 UITableViewIos Swift-UITableView cell.detailTextLable.text不可见,ios,uitableview,swift,Ios,Uitableview,Swift,我一直在尝试StackOverFlow中的所有方法以使其工作,但我没有运气 UITableView单元格.textLabel显示正确,但未正确显示单元格.detailTextLable func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 3 } func tableView(tableView: UITableView, cellForRowAtInd
单元格.textLabel
显示正确,但未正确显示单元格.detailTextLable
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "cell"
var cell : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: cellIdentifier)
}
cell!.textLabel?.text = "hello"
cell!.detailTextLabel?.text = "world"
return cell!
}
我注意到在其他教程中,最后3个细胞系没有textlab
或detailtextlab
上的选项,但是如果我没有选项,XCode会抛出错误。也许这是其他地方出错的迹象
编辑:我如何创建实际的UITableView
var dataTable : UITableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
dataTable.frame = CGRectMake(0, 300, 200, 200)
dataTable.delegate = self
dataTable.dataSource = self
dataTable.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.view.addSubview(dataTable)
}
注册UITableViewCell类时,保证获得一个单元格,并且该单元格将是没有detailTextLabel的基本单元格。因此,“if cell==nil”子句将永远不会运行。只需删除register class语句,您的代码就会正常工作。您是否在IB中将单元格设置为“subtitle”类型?@rdelmar我没有使用IB创建单元格,单元格是在上面的代码中创建的。还是说桌子本身?我通过
var-dataTable:UITableView=UITableView()
dataTable.frame=CGRectMake(0300200)
dataTable.delegate=self
dataTable.dataSource=self
dataTable.registerClass(UITableViewCell.self,forCellReuseIdentifier:“cell”)self.view.addSubview(dataTable)