大家好,我得到了这段代码并得到一个警告“不兼容的指针初始化带有NSString类型的表达式的NSMutableString”和一个mem泄漏。有谁似乎知道如何纠正这个?
- (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;
}
thnaks
答案 0 :(得分:3)
要摆脱不兼容的指针警告,您需要将self.textField.text
的可变副本分配给value
:
NSMutableString *value = (self.textField.text == nil ? [NSMutableString new] : [self.textField.text mutableCopy] );