NSMutableString setString
我是 XCode 编程新手,作为第一个熟悉练习,我想制作一个小型计算器应用程序。显然我遇到了一些问题: 我尝试让用户使用按钮将数字和运算符输入到字符串中,然后他就会看到该字符串。当我使用时
displayString = [NSString stringWithFormat:@"%@%@", displayString, operatorString];
一切正常。然后我决定使用 NSMutableStrings 来获取删除按钮。我适当地更改了头文件,之后我仍然使用早期的 NSString 功能(?因为 NSMutableString 继承自 NSString?)然后我遇到了以下问题:
[displayString setString:@"test"];
NSLog(@"%@", displayString);
即使这是我调用的第一个方法,我仍然得到 nul。我 我做错了什么?
不相关的是,有没有办法让这个字符串写入某种函数:我希望能够做
result = contentof:displayString
或类似的事情。 我有什么想法可以做到这一点吗?
I am new to programming in XCode, and as a first familiarisation exercise, I would like to make a small Calculator app. So obviously I came upon a few problems:
I try to have the user use buttons to type the digits and operators into a string, which he then sees. When I use
displayString = [NSString stringWithFormat:@"%@%@", displayString, operatorString];
everything works fine. Then I decided to work with NSMutableStrings in order to get deletebuttons. I changed the headerfile appropriately, after which I still the earlier NSString functionality (? because NSMutableString inherits from NSString?) And then I got the following problem:
[displayString setString:@"test"];
NSLog(@"%@", displayString);
Even when this is the first method I call, I still get nul. I
What am I doing wrong?
Unrelated, is there a way to have this string write to a sort of function: I would like to be able to do
result = contentof:displayString
or something a like.
Any ideas in how I could do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSString
没有setString:
方法。 (文档 )对于这种情况,您需要一个
NSMutableString
。以下是实现它的方法:...然后更改它:
NSString
doesn't have asetString:
method. (Documentation)For this case, you'd need an
NSMutableString
. Here's how you'd implement it:... and then to change it: