I'm newbie in IOS development. How to set text for detailTextLabel, which in the second row using Swift?
I need something like this, but for the specific detailTextLabel:
cell.detailTextLabel?.text = "Text"
Ah I see, your problem is that you don't know how to change the text for each cell in your
UITableView - your current method is obviously setting the same text for every cell.
Well what you need is an array with your different texts which allows you to add a different text string in each cell. The following is a basic example of how this can be done in
Declare an array in your header (.h) file like so:
In your implementation (.m) file, populate the array in your
viewDidLoad method like so:
// Make an array and populate it. detailArray = @[@"text one", @"text two", nil]; // etc....
When you are setting the
detailTextLabel in your
UITableView delegate methods, do the following to set the text label from the strings stored in the array:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", detailArray[indexPath.row]];