如何使 2 个标签彼此相加?
你好,我对 Xcode 有点陌生,我正在尝试制作一个应用程序,你按下一个按钮,数字就会上升;我有 2 个按钮和 2 个标签。我已经完成了两个标签的计数,但现在我希望两个标签中的数字相加并显示在不同的标签中。我是否可以向按钮添加任何行,以使它们也在其他标签中计数,或者我是否需要有单独的操作和/或按钮?
谢谢
Hi I'm kinda new to Xcode and I'm trying to make an app where you press a button and the number will go up; and I have 2 buttons and 2 labels. I've got it to where the 2 labels will count up, but now I'm wanting the numbers from both labels to add together and show in a different label. Is there any line I can add to the buttons to make them just count up in the other label as well or do I need to have a separate action and/or button?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
直接说:
应该可以,只需确保将我使用的指针替换为您正在使用的指针即可。
Straight up:
Should work, just make sure to replace the pointers I used with the ones you're using.
esqew 的答案可以解决问题,但格式说明符不正确。
如果变量
sum
实际上是一个int
...应该是:
%@
用于 Objective-C 对象,int
不是 Objective-C 对象。参考:
http://developer.apple。 com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
esqew's answer would do the trick, but the format specifier is incorrect.
If the variable
sum
is in fact anint
...should be:
%@
is for Objective-C objects, anint
is not an Objective-C object.Reference:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html