为什么应用程序在 iPhone 模拟器中崩溃;我该如何解决这个问题?
我正在开发一个使用导航控制器的应用程序。当我构建时,我没有收到任何错误或警告。我在 FirstViewController.m
文件中定义了一个方法 myMethod
,然后在 viewDidLoad
中使用 [self myMethod]; 调用该方法。
。
当我从控制台构建并运行时,我什么也没得到。因此,我将 NSLog() 语句如下所示:
-(void) viewDidLoad {
NSLog(@"Entering viewDidLoad");
[self myMethod];
NSLog(@"Called myMethod");
[super viewDidLoad];
}
控制台永远不会返回第二个 NSLog 语句,这让我相信应用程序在调用该方法时崩溃了。
我已经将模拟器设置为 iOS 4.0.1 和 iOS 4.1 进行了尝试。我正在针对 iOS 4.1 SDK 进行构建。我非常感谢您能提供的任何帮助。
更新:我运行了调试器,它似乎显示问题出在 myMethod
中。在收到“EXC_BAD_ACCESS”之前,我只在该方法中执行了几行代码。代码行是:
-(void)myMethod {
NSMutableArray *someStuff;
NSMutableArray *someMoreStuff;
stuffSections=[[NSMutableArray alloc] initWithObjects:@"Some Stuff",@"Some More Stuff",nil];
someStuff=[[NSMutableArray alloc] init];
someMoreStuff=[[NSMutableArray alloc] init];
[someStuff addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Item Name",@"name",@"Item Picture.png",@"picture",@"http://theurl.net/",@"url",@"1",@"itemCode",nil]];
但看来我无法通过第一次尝试向 someStuff
数组添加一些内容。
I'm working on an app that uses a navigation controller. When I build, I get no errors or warnings. I've defined a method myMethod
in FirstViewController.m
file, then in viewDidLoad
I call the method with [self myMethod];
.
When I built and ran from the Console, I got nothing. So I put NSLog()
statements like so:
-(void) viewDidLoad {
NSLog(@"Entering viewDidLoad");
[self myMethod];
NSLog(@"Called myMethod");
[super viewDidLoad];
}
The Console never returns the second NSLog statement, leading me to believe that the app crashes while calling the method.
I've tried this with the simulator set to iOS 4.0.1 as well as iOS 4.1. I'm building against the iOS 4.1 SDK. I really appreciate any help you can offer.
Update: I ran the Debugger, which seems to show the problem being in myMethod
. I only make it through a few lines of code in that method before I receive "EXC_BAD_ACCESS". The lines of code are:
-(void)myMethod {
NSMutableArray *someStuff;
NSMutableArray *someMoreStuff;
stuffSections=[[NSMutableArray alloc] initWithObjects:@"Some Stuff",@"Some More Stuff",nil];
someStuff=[[NSMutableArray alloc] init];
someMoreStuff=[[NSMutableArray alloc] init];
[someStuff addObject:[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Item Name",@"name",@"Item Picture.png",@"picture",@"http://theurl.net/",@"url",@"1",@"itemCode",nil]];
But it appears that I can't get past this first attempt to add something to the someStuff
array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来“myMethod”有问题。如果我不得不猜测,我会说您正在尝试引用一个自动释放且未保留的对象。
Looks like there is a problem in "myMethod". If I had to guess, I would say you are trying to reference an object that was auto-released and not retained.
初始化 someStuff 和 someMoreStuff 时缺少分配。应该是
You're missing the alloc when initializing someStuff and someMoreStuff. It should be
你交叉检查过这两个 MutableArray 吗?是否已分配成功?当应用进入损坏状态(通常是由于内存管理问题)时,您会收到“EXC_BAD_ACCESS”。我猜数组没有分配。
尝试这样分配。
添加断点,检查调试区域并确认它们是否分配成功。如果每个数组都有内存,那么它们就会被分配。
Have you cross checked the two MutableArrays? Do they have been allocated successfully? You get "EXC_BAD_ACCESS" when the app got into a corrupted state that is usually due to a memory management issue. I guess the arrays are not allocated.
Try allocating this way.
add a breakpoint there are check in the debug area and confirm whether they are being allocated successfully. If there is a memory to each of these array, then they are allocated.