Object-C字符串拼接问题

jc544392727 2016-03-25 06:18:11
//这一段是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)
...全文
691 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shouthinJing 2017-06-20
  • 打赏
  • 举报
回复
如果Mystring是NSString类型,可以用stringByAppendingString:追加, Mystring=[Mystring stringByAppendingString[sender currentTitle]];
hpcph 2016-04-11
  • 打赏
  • 举报
回复
// 将字符串内容转换成 double 类型 [@"123.123" doubleValue];
hpcph 2016-04-11
  • 打赏
  • 举报
回复
NSLog(@"%f",[@"123.123" doubleValue]);
奋斗___ 2016-04-11
  • 打赏
  • 举报
回复
1楼正解。楼主可试试
宇仔TuT 2016-03-30
  • 打赏
  • 举报
回复
楼上说的没错,可以试试string = [string appendString:.....]
tcmakebest 2016-03-25
  • 打赏
  • 举报
回复
NSMutableString 才有 appendString 方法吧,类型改一下就行不影响使用

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧