Database Swift从数据库检索数据
我查阅了很多教程,但找不到我想做的事情。 我想做的是在我的数据库中存储GPS坐标;到目前为止没有问题。在我的tableViewControllerCell中,我不想使用“subtitle”样式,而是使用UILabel。我的问题是我有这个代码,它与“subtitle”风格很好地配合(见下文)。但我想做我自己的自定义标签 有人能帮我吗Database Swift从数据库检索数据,database,swift,xcode6,Database,Swift,Xcode6,我查阅了很多教程,但找不到我想做的事情。 我想做的是在我的数据库中存储GPS坐标;到目前为止没有问题。在我的tableViewControllerCell中,我不想使用“subtitle”样式,而是使用UILabel。我的问题是我有这个代码,它与“subtitle”风格很好地配合(见下文)。但我想做我自己的自定义标签 有人能帮我吗 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NS
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
let list = frc.objectAtIndexPath(indexPath) as! List
cell.textLabel?.text = list.item
var qty = list.qty
var note = list.note
cell.detailTextLabel?.text = "Qty:\(qty) -\(note)"
return cell
您需要创建一个自定义UITableViewCell,例如myTableViewCell,将其分配给故事板中的单元,选择单元并在inspector中选择类(与您为视图控制器所做的相同) 之后,在检索单元格时,必须将其强制转换为新类,如下所示:
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! myTableViewCell
现在可以在单元格中调用属性,如
cell.myField = "value"
因此,基本上您想知道如何为表视图使用自定义视图单元格 如果要在序列图像板中创建自定义表格视图单元,请执行以下操作:
UITableViewCell
类class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var labelName: UILabel!
@IBOutlet weak var labelCustom: UILabel!
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell
let data = something[indexPath.row]
cell.labelName.text = data.name
cell.labelCustom.text = String(data.number)
return cell
}
谢谢你的帮助,我确实有一些问题要解决。我会努力解决它,然后再回来找你。再次感谢你我确实相信我做了你所说的,但我一直有这个错误。UItableViewCell没有名为label的成员。我确实有一个IBOulet作为我的标签名“label”。此错误可能由以下几方面引起。创建单元格时是否将其强制转换到自定义表视图单元格?