NSMutableString appendString生成SIGABRT错误 [英] NSMutableString appendString generates SIGABRT Error

查看:86
本文介绍了NSMutableString appendString生成SIGABRT错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有新的(这个论坛和Xcode一般),所以请耐心等待。

New here (this forum and Xcode in general), so bear with me.

在过去的几天里,我花了几个小时的时间试着去追踪我在这里做错了什么,但我似乎无法确定我的问题。

I've spent multiple hours off and on over the last severals days trying to track down what exactly that I'm doing wrong here, but I just don't seem to be able to pinpoint my issue.

这是我的代码的相关部分(我相信)。

Here's the relevant sections of my code (I believe).

在标题中:

@interface BlahViewController : UIViewController {

  NSMutableString *display;

}

@property (nonatomic, retain) NSMutableString *display;

主要:

@implementation BlahViewController

@synthesize display;

- (void)viewDidLoad {
    self.display = [[NSMutableString alloc] init];  
}

- (void)anotherFunction:(UIButton *)sender {

    NSString *info = [[sender titleLabel] text];

    [self.display appendString:info];
}

我运行代码,按下UIButton,我收到错误消息。这是最初的抛出:

I run the code, press the UIButton, and I get an error. Here's the initial throw:

  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM appendString:]: unrecognized selector sent to instance 0x4e3d300' ***

谢谢!

编辑:请求整个堆栈跟踪,所以在这里(在查看堆栈后我意识到可能存在混淆,我现在正在编写一个非常基本的计算器,所以ViewController等应该在这个特殊情况下考虑背景和anotherFunction=digitPressed):

The whole stack trace was requested, so here it is (after reviewing the stack I realize there may be confusion, I'm writing a very basic calculator currently, so the ViewController, etc, should consider that backdrop and "anotherFunction" = "digitPressed" in this particular case):

* 第一次投掷时调用堆栈:

* Call stack at first throw: (


0 CoreFoundation 0x00e345a9 exceptionPreprocess + 185

1 libobjc.A.dylib 0x00f88313 objc_exception_throw + 44 < br>
2 CoreFoundation 0x00e360bb - [NSObject(NSObject)doesNotRecognizeSelector:] + 187

3 CoreF oundation 0x00da5966 __ 转发
+ 966

4 CoreFoundation 0x00da5522 _CF_forwarding_prep_0 + 50

5计算器0x0000273b - [CalculatorViewController digitPressed:] + 113

6 UIKit 0x002bb4fd - [UIApplication sendAction:to:from:forEvent:] + 119

7 UIKit 0x0034b799 - [UIControl sendAction:to:forEvent:] + 67

8 UIKit 0x0034dc2b - [UIControl(内部)_sendActionsForEvents:withEvent:] + 527

9 UIKit 0x0034c7d8 - [UIControl touchesEnded:withEvent:] + 458

10 UIKit 0x002dfded - [UIWindow _sendTouchesForEvent:] + 567

11 UIKit 0x002c0c37 - [UIApplication sendEvent:] + 447

12 UIKit 0x002c5f 2e _UIApplicationHandleEvent + 7576

13 GraphicsServices 0x01723992 PurpleEventCallback + 1550

14 CoreFoundation 0x00e15944 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52

15 CoreFoundation 0x00d75cf7 __CFRunLoopDoSource1 + 215

16 CoreFoundation 0x00d72f83 __CFRunLoopRun + 979

17 CoreFoundation 0x00d72840 CFRunLoopRunSpecific + 208

18 CoreFoundation 0x00d72761 CFRunLoopRunInMode + 97

19 GraphicsServices 0x017221c4 GSEventRunModal + 217

20 GraphicsServices 0x01722289 GSEventRun + 115

21 UIKit 0x002c9c93 UIApplicationMain + 1160

22计算器0x00002254 main + 102

23计算器0x000021e5 start + 53



在抛出'NSException'实例后终止调用


当前语言:auto;目前objective-c

0 CoreFoundation 0x00e345a9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f88313 objc_exception_throw + 44
2 CoreFoundation 0x00e360bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00da5966 __forwarding
+ 966
4 CoreFoundation 0x00da5522 _CF_forwarding_prep_0 + 50
5 Calculator 0x0000273b -[CalculatorViewController digitPressed:] + 113
6 UIKit 0x002bb4fd -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x0034b799 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x0034dc2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9 UIKit 0x0034c7d8 -[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x002dfded -[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x002c0c37 -[UIApplication sendEvent:] + 447
12 UIKit 0x002c5f2e _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x01723992 PurpleEventCallback + 1550
14 CoreFoundation 0x00e15944 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
15 CoreFoundation 0x00d75cf7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00d72f83 __CFRunLoopRun + 979
17 CoreFoundation 0x00d72840 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00d72761 CFRunLoopRunInMode + 97
19 GraphicsServices 0x017221c4 GSEventRunModal + 217
20 GraphicsServices 0x01722289 GSEventRun + 115
21 UIKit 0x002c9c93 UIApplicationMain + 1160
22 Calculator 0x00002254 main + 102
23 Calculator 0x000021e5 start + 53
)
terminate called after throwing an instance of 'NSException'
Current language: auto; currently objective-c


推荐答案


*终止应用由于未被捕获的
异常
'NSInvalidArgumentException',原因:
' - [__ NSArrayM appendString:]:
无法识别的选择器发送到实例
0x4e3d300'*

这表明你正在调用 appendString:某种实例 NSArray ,显然无效。

This indicates that you are calling appendString: an instance of some kind of NSArray, which obviously won't work.

假设 [self.display appendString :info]; 是异常的实际来源,然后它发生了,因为 self.display 可能已被过度释放,巧合的是,一个 NSArray 实例分配在内存中的同一个地方。

Assuming that [self.display appendString:info]; is the actual source of the exception, then it is happening because self.display has likely been over-released and, coincidentally, an NSArray instance was allocated at the same place in memory.

您可以使用僵尸检测来调试它。

You could use zombie detection to debug this.

或者,您可能在某处损坏了内存。或者,也许还有另一个分配给显示

Alternatively, you might be corrupting memory somewhere. Or, maybe, there is another assignment to display.

无论如何,每当你遇到崩溃,那里将是一个回溯。请发布。有可能在其他地方发生崩溃。

In any case, whenever you have a crash, there will be a backtrace. Please post it. There is the off chance that the crash is happening somewhere else.

5 Calculator 0x0000273b -[CalculatorViewController digitPressed:] + 113

显示的来源digitPressed:方法。

self.display = [[NSMutableString alloc] init];  

这是内存泄漏;它会被保留两次。只需 self.display = [NSMutableString string]; self.display = nil; (在你的<$ c中) $ c> viewDidUnload )。

That is a memory leak; it'll be retained twice. Just do self.display = [NSMutableString string]; and self.display = nil; (in your viewDidUnload).

但这不是问题的根源;有些东西正在重置显示变量它被过度释放。显示显示的所有用途

But that isn't the source of your problem; something is resetting the display variable or it is being over-released. Show all uses of display.

这篇关于NSMutableString appendString生成SIGABRT错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆