//这一段是ViewController.m中的一段,是计算器小程序中,按下数字键在show的label中显示的
//想把按下的数字做成字符串并转为double,用于计算
- (IBAction)digPress:(id)sender {
    //UIButton *btm=(UIButton*)sender;
    
    if (_show.text==nil) {
        _show.text=[sender currentTitle];
    }
    [Mystring appendString:[sender currentTitle]];//这段追加代码会崩溃
    Mystring=[sender currentTitle];
   
    _show.text=Mystring;
    
}以下是log:2016-03-25 18:22:57.882 Mycalculator[785:55329] -[NSTaggedPointerString appendString:]: unrecognized selector sent to instance 0xa000000000000381
2016-03-25 18:22:57.906 Mycalculator[785:55329] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString appendString:]: unrecognized selector sent to instance 0xa000000000000381'
*** First throw call stack:
(
0   CoreFoundation                      0x000000010f28fd85 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010ed03deb objc_exception_throw + 48
2   CoreFoundation                      0x000000010f298d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010f1decfa ___forwarding___ + 970
4   CoreFoundation                      0x000000010f1de8a8 _CF_forwarding_prep_0 + 120
5   Mycalculator                        0x000000010e801350 -[ViewController digPress:] + 256
6   UIKit                               0x000000010f647a8d -[UIApplication sendAction:to:from:forEvent:] + 92
7   UIKit                               0x000000010f7bae67 -[UIControl sendAction:to:forEvent:] + 67
8   UIKit                               0x000000010f7bb143 -[UIControl _sendActionsForEvents:withEvent:] + 327
9   UIKit                               0x000000010f7ba263 -[UIControl touchesEnded:withEvent:] + 601
10  UIKit                               0x000000010f6ba99f -[UIWindow _sendTouchesForEvent:] + 835
11  UIKit                               0x000000010f6bb6d4 -[UIWindow sendEvent:] + 865
12  UIKit                               0x000000010f666dc6 -[UIApplication sendEvent:] + 263
13  UIKit                               0x000000010f640553 _UIApplicationHandleEventQueue + 6660
14  CoreFoundation                      0x000000010f1b5301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15  CoreFoundation                      0x000000010f1ab22c __CFRunLoopDoSources0 + 556
16  CoreFoundation                      0x000000010f1aa6e3 __CFRunLoopRun + 867
17  CoreFoundation                      0x000000010f1aa0f8 CFRunLoopRunSpecific + 488
18  GraphicsServices                    0x0000000112b0fad2 GSEventRunModal + 161
19  UIKit                               0x000000010f645f09 UIApplicationMain + 171
20  Mycalculator                        0x000000010e801aef main + 111
21  libdyld.dylib                       0x0000000111a6992d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

解决方案 »

  1.   

    NSMutableString 才有 appendString 方法吧,类型改一下就行不影响使用
      

  2.   

    楼上说的没错,可以试试string = [string appendString:.....]
      

  3.   

    // 将字符串内容转换成 double 类型
    [@"123.123" doubleValue];
      

  4.   

    NSLog(@"%f",[@"123.123" doubleValue]);
      

  5.   

    如果Mystring是NSString类型,可以用stringByAppendingString:追加,
    Mystring=[Mystring stringByAppendingString[sender currentTitle]];