Objective c 目标-c….通过按钮从我的标签中删除编号

Objective c 目标-c….通过按钮从我的标签中删除编号,objective-c,Objective C,我想通过此按钮从我的标签中逐个删除数字 NSMutableString*str=(NSMutableString*)label.text str=[str replaceCharacterInRange:NSMakeRange([str length]-1,1),带字符串:@”“ 错误….“无效值未被忽略,因为它应该是”您不能将NSString强制转换为NSMutableString,并期望它是可变的。在更改之前,您需要创建一个可变字符串 NSMutableString *mutableStri

我想通过此按钮从我的标签中逐个删除数字
NSMutableString*str=(NSMutableString*)label.text

str=[str replaceCharacterInRange:NSMakeRange([str length]-1,1),带字符串:@”“


错误….
“无效值未被忽略,因为它应该是”

您不能将
NSString
强制转换为
NSMutableString
,并期望它是可变的。在更改之前,您需要创建一个可变字符串

NSMutableString *mutableString = [label.text mutableCopy];
[mutableString replaceCharactersInRange:NSMakeRange([mutableString length] - 1, 1) withString:@""];

replaceCharacterInRange:with字符串:
返回void,因为它是修改字符串的可变操作

要解决您的问题,您需要知道的第一件事是,您不能仅通过将字符串强制转换为
NSMutableString
而使其可变。您需要使用
mutableCopy

NSMutableString *str= [label.text mutableCopy];

//Now the next thing do not assign str
[str replaceCharacterInRange:NSMakeRange([str length]-1,1) withString:@""];

...
//And finally when you are done if you are not using ARC 
///then you need to release the string since you called `mutableCopy`.
[str release];

使用DeleteCharactersRange:

[str deleteCharacterInRange:NSMakeRange([str length]-1,1) ])]

请澄清你的问题。我不明白你还有什么问题。