当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Change specific detailLabelText

问题描述:

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 Objective-C

Declare an array in your header (.h) file like so:

NSArray *detailArray;

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]];
分享给朋友:
您可能感兴趣的文章:
随机阅读: