如何以从左到右的格式将 NSMutable 数组打印到 UILabel 中,并在对象之间包含间距?

发布于 2025-01-06 05:05:27 字数 300 浏览 3 评论 0原文

我有一个计算器,在它的控制器中我有一个存储对象的 NSMutable 数组。它是一个 RPN 计算器,例如,如果我输入 357(按 Enter)、589(按操作键 +),则对象将以以下格式推入数组中: NSMutableArray *completeOperations([0]:357, [1]:589 ,[2]:+) - 不确定这在语法上是否正确,但我只是想传达这个想法。所以我想做的就是将此数组打印到 UILabel 中,属性:fullPerformDisplay,格式为 357 589 + =。如图所示,当我打印对象时,我需要在对象之间添加空格,并且需要以从左到右的格式打印。

I have a calculator and in its controller i have a NSMutable array which stores objects. It's a RPN calculator so for example if I type 357 (Hit Enter), 589 (Hit operation key +), then objects are pushed into the array in this format: NSMutableArray *completeOperations([0]:357, [1]:589, [2]:+) - not sure if this is syntactically correct but I'm just trying to get the idea across. So what I want to do is print this array into the UILabel, property: fullPerformDisplay, in the format 357 589 + =. As shown I need to add spaces in between the objects when I print them and it need to print in a left to right format.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深缘浅 2025-01-13 05:05:27

如果它们在数组中,您可以连接数组的组件并使用 [NSArray ComponentsJoinedByString:] 将其转换为字符串

NSArray *array = [NSArray withObjects: @"357", @"589", @"+", nil];
NSString *string = [array componentsJoinedByString:@" "];
// string will contain @"357 589 +"

UILabel *label = [[UILabel alloc] init];
label.text = string;

If they are in an array you can join the components of an array and convert it to a string with [NSArray componentsJoinedByString:]

NSArray *array = [NSArray withObjects: @"357", @"589", @"+", nil];
NSString *string = [array componentsJoinedByString:@" "];
// string will contain @"357 589 +"

UILabel *label = [[UILabel alloc] init];
label.text = string;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文