大家好,我收到了这段代码,并收到警告“使用 NSString 类型的表达式初始化 NSMutableString 的不兼容指针”和内存泄漏。有人知道如何纠正这个问题吗?
- (IBAction)numberClicked:(id)sender {
UIButton * numberBtn = (UIButton*)sender;
NSMutableString *value = (self.textField.text == nil ? [NSMutableString new] : self.textField.text );
[value appendString:[NSString stringWithFormat:@"%d",numberBtn.tag]];
self.textField.text = value;
}
谢谢
最佳答案
要消除不兼容的指针警告,您需要将 self.textField.text
的可变副本分配给 value
:
NSMutableString *value = (self.textField.text == nil ? [NSMutableString new] : [self.textField.text mutableCopy] );
关于iphone - 使用 NSString 类型的表达式初始化 NSMutableString 的指针不兼容 - 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8766103/