Reputation: 33
Im current developing an application in Swift that stores data to a table. At the moment I am having an issue with the subtitle text under the main text. Im wanting to add several lines of subtitles under "Licence Number" refer to the image. I. Ive got everything ready to go but not to sure how to make it visible. Any help would be appreciated
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: "Nil")
cell.textLabel!.text = LrnLog.logs[indexPath.row].name //Trip Date- The data is used for the name
cell.detailTextLabel!.text = LrnLog.logs[indexPath.row].desc //Trip Name
cell.detailTextLabel!.text = LrnLog.logs[indexPath.row].rego //Vehicle Rego
cell.detailTextLabel!.text = LrnLog.logs[indexPath.row].licnum //License Number
return cell
}
Image 2 is what my app is looking like
Upvotes: 2
Views: 2731
Reputation: 2914
You should assign the text
at once in one control flow(or within one block of code), you cannot reassign different texts to the same property immediately one after the other. If you do that then the compiler will consider latest one not all. So to answer your question try this in your cellForRowAtIndexPath:
cell.detailTextLabel!.numberOfLines = 0
cell.textLabel!.text = LrnLog.logs[indexPath.row].name
cell.detailTextLabel!.text = "\(LrnLog.logs[indexPath.row].desc)\n\(LrnLog.logs[indexPath.row].rego)\n\(LrnLog.logs[indexPath.row].licnum)"
Assuming that none of the above attributes in LrnLog.logs[indexPath.row]
are nil
else it will crash. So better check for nil
and then assign the values. Also you need to adjust the size of the cells as your subtitle lines are going high.
Upvotes: 6
Reputation: 1836
You are changing the text of the label 3 times, not actually changing different labels.
You can either add all of those strings together, and have them on one line, OR you need to put 3 separate labels in your cell. Also following with the comment on your question, you can set the number of lines to 0, but you still must combine this into one string. Also, I'm assuming you will want to put data to the right of that information as well, and in that case a custom cell is really your best option.
If you decide to create a custom cell you will also want to create a custom TableViewCell class for you cell, and you would drag all of your outlets to it.
Upvotes: 1