UILabel 没有收到我写入的内容
写这个主题很棘手。我想这是一个基本问题,但我似乎找不到答案。 代码本身显示了我想要执行的操作,而 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 确实输出了正确的内容。 这里发生了什么我没有看到的事情?
Tricky to write the subject to this. I guess this is a basic question but I can't seem to find the answer.
The code itself shows what I wanna do and the UILabel don't show anything, the first line I add to it works fine, but not when I try to write out the array:
-(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"];
}
}
The NSLog do put out the right stuff.
What is gong on here, that I am not seeing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
还给你自由2024-12-02 08:56:47
这是我自己的问题的解决方案。希望它可以帮助别人。
NSArray *pastMusicArray = [pastSongs getHistory];
musicHistory = [[NSMutableString alloc] init];
historyLabel.numberOfLines = 0;
for(int t=2; t<[pastMusicArray count]; t++) {
[musicHistory appendString:[[pastMusicArray objectAtIndex:t] capitalizedString]];
[musicHistory appendString:@"\n"];
}
historyLabel.text = musicHistory;
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
在我看来,问题在于您每次都设置全文,而最后一个 setText: 带有 @"\n" 这是一个不可见的字符串。尝试附加而不是设置文本。类似于:
这会将@“TextToAppend”附加到标签中的当前文本值。
更新:请注意,我使用的是文本属性而不是设置器。
相当于
Seems to me that the problem is that you are setting the full text each time and the last setText: is with @"\n" which is an invisible string. Try appending instead of setting the text. Something like:
This will append @"TextToAppend" to the current text value in the label.
Update: Notice I'm using the text property rather than the setter.
is equivalent to