gpt4 book ai didi

ios - UILabel 没有收到我写入的内容

转载 作者:行者123 更新时间:2023-11-29 05:01:41 24 4
gpt4 key购买 nike

写这个主题很棘手。我想这是一个基本问题,但我似乎找不到答案。代码本身显示了我想要做的事情,而 UILabel 没有显示任何内容,我添加到其中的第一行工作正常,但当我尝试写出数组时则不然:

-(IBAction)getSongHistory:(id)sender {
[historyLabel setText:@"test write\n test write another line"];
NSArray *pastMusicArray = [pastSongs getHistory];
for(int t=2; t<[pastMusicArray count]; t++) {
NSString *tempRow = [pastMusicArray objectAtIndex:t];
//NSLog(@"%@", tempRow);
[historyLabel setText:tempRow];
[historyLabel setText:@"\n"];
}

NSLog 确实输出了正确的内容。这里有什么我没有看到的锣?

最佳答案

在我看来,问题在于您每次都设置全文,而最后一个 setText: 带有 @"\n"这是一个不可见的字符串。尝试附加而不是设置文本。像这样的东西:

historyLabel.text = [NSString stringWithFormat:@"%@%@", historyLabel.text,@"TextToAppend"];

这会将@“TextToAppend”附加到标签中的当前文本值。

更新:请注意,我使用的是文本属性而不是 setter 。

historyLabel.text = @"Some Text";

相当于

[historyLabel setText:@"Some Text"];

关于ios - UILabel 没有收到我写入的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6788197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com