[英]How can I programmatically determine if my app is running in the iphone simulator?
[英]Why is app crashing in iPhone simulator; how can I fix this?
我正在開發一個使用導航控制器的應用程序。 構建時,沒有任何錯誤或警告。 我在FirstViewController.m
文件中定義了方法myMethod
,然后在viewDidLoad
使用[self myMethod];
調用該方法[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
數組添加內容的嘗試。
您是否已交叉檢查了兩個MutableArrays? 是否已成功分配它們? 當應用程序進入損壞狀態(通常是由於內存管理問題)時,您將獲得“ EXC_BAD_ACCESS ”。 我猜數組沒有分配。
嘗試以這種方式分配。
NSMutableArray * someStuff = [[NSMutableArray alloc]initWithCapacity:3];
NSMutableArray * someMoreStuff = [[NSMutableArray alloc]initWithCapacity:3];
添加一個斷點,在調試區域中進行檢查,並確認是否已成功分配它們。 如果這些數組中的每一個都有一個內存,則將對其進行分配。
看起來“ myMethod”中有問題。 如果我不得不猜測,我會說您正在嘗試引用自動釋放但未保留的對象。
初始化someStuff和someMoreStuff時,您會丟失分配。 它應該是
someStuff = [[NSMutableArray alloc] init];
someMoreStuff = [[NSMutableArray alloc] init];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.