gpt4 book ai didi

iphone - 如何将 NSMutableArray 元素计数的文本输出到 iPhone 标签

转载 作者:行者123 更新时间:2023-11-28 22:49:56 26 4
gpt4 key购买 nike

NSUInteger arrayLength = [annotations count];

UILabel* arrayLengthLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
arrayLengthLabel.text = @"%@", arrayLength;
[self.view addSubview:arrayLengthLabel];

我有上面的代码,我已经研究过了。

问题出在将数组长度计数输出到标签时。

我应该在数组中有 4 个元素,但这并没有输出元素的数量,我确定我在这里犯了一个小学生错误。

提前求助加油

最佳答案

这是我要使用的代码:

int arrayLength = [annotations count];
UILabel* arrayLengthLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)];
arrayLengthLabel.text = [NSString stringWithFormat:@"%i",arrayLength];
[self.view addSubview:arrayLengthLabel];

我正在使用标准 int 并使用代码 %i 而不是 %@。这可能是你的问题。我不知道 NSUInteger 是否需要 %i,但我绝对知道 int 使用 %i

此外,我不知道您执行 NSString 的方式是否在未经测试的情况下工作,所以我使用了“完整”格式,我知道它绝对有效。

关于iphone - 如何将 NSMutableArray 元素计数的文本输出到 iPhone 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12250752/

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