更改特定详细信息LabelText

时间:2015-06-30 06:03:18

标签: ios objective-c xcode swift uitableview

我是IOS开发的新手。如何设置detailTextLabel的文本,在第二行使用Swift?

我需要这样的东西,但是对于具体的detailTextLabel:

cell.detailTextLabel?.text = "Text"

1 个答案:

答案 0 :(得分:0)

我知道,您的问题是您不知道如何更改UITableView中每个单元格的文本 - 您当前的方法显然是为每个单元格设置相同的文本。

您需要的是一个包含不同文本的数组,允许您在每个单元格中添加不同的文本字符串。以下是如何在Objective-C

中完成此操作的基本示例

在标题(.h)文件中声明一个数组,如下所示:

NSArray *detailArray;

在您的实现(.m)文件中,使用viewDidLoad方法填充数组,如下所示:

// Make an array and populate it.
detailArray = @[@"text one", @"text two", nil]; // etc....

detailTextLabel委托方法中设置UITableView时,请执行以下操作以从存储在数组中的字符串设置文本标签:

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", detailArray[indexPath.row]];