因此,我有一個非常奇怪的問題,當我在模擬器上運行我的應用程序並插入iPad(在插入電纜的設備上運行應用程序)時,它一切正常。它的插入,我試圖使用的應用程序後,在設備上運行後,但是,它崩潰..試圖尋找在設備崩潰日誌,我看到:僅在設備上運行應用程序時發生崩潰問題
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3672bf78 objc_msgSend + 16
1 App 0x000ca834 -[AHAppImageData dealloc] (AHInstagramImageData.m:122)
2 libobjc.A.dylib 0x3672d16e _objc_rootRelease + 30
3 CoreFoundation 0x33d792e0 CFRelease + 88
4 CoreFoundation 0x33d8ea30 -[__NSArrayM removeObjectAtIndex:] + 288
5 CoreFoundation 0x33d84adc -[NSMutableArray removeAllObjects] + 64
6 App 0x000f717e -[AHImageDataSource clearDataSource] (AHImageDataSource.m:53)
7 App 0x000c0a36 __49-[AHMainViewController loadRequestWithURLString:]_block_invoke_0 (AHMainViewController.m:91)
8 libdispatch.dylib 0x32658c52 _dispatch_call_block_and_release + 6
9 libdispatch.dylib 0x3265aee0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 188
10 CoreFoundation 0x33e032a6 __CFRunLoopRun + 1262
11 CoreFoundation 0x33d8649e CFRunLoopRunSpecific + 294
12 CoreFoundation 0x33d86366 CFRunLoopRunInMode + 98
13 GraphicsServices 0x37d68432 GSEventRunModal + 130
14 UIKit 0x36820cce UIApplicationMain + 1074
15 App 0x000b2860 main (main.m:16)
16 App 0x000b2820 0xb1000 + 6176
知道爲什麼這僅僅發生在設備和當插入或模擬器運行應用程序時不行?
基於下面的評論,我顯示,負責該代碼:
[[AHMyAppAPIClient sharedClient] getPath:requestURLPath parameters:nil
success:^(AFHTTPRequestOperation *operation, id response) {
[self.progressHUD_ hide:YES];
self.nextPaginationURL_ = [[response valueForKey:@"pagination"] valueForKey:@"next_url"];
[self.collectionView_.pullToRefreshView stopAnimating];
[[NSOperationQueue sharedOperationQueue] cancelAllOperations];
NSArray *arr = [response valueForKey:@"data"];
if ([arr count] > 0){
[[AHImageDataSource sharedDataSource] clearDataSource];
}
for (NSDictionary * data in arr){
AHInstagramImageData * imgData = [[AHInstagramImageData alloc] initWithData:data];
[[AHImageDataSource sharedDataSource] addObject:imgData];
[imgData release];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.collectionView_ setContentOffset:CGPointMake(0, 0)];
[self.collectionView_ reloadData];
});
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self.progressHUD_ hide:YES];
NSLog(@"Error fetching user data!");
NSLog(@"%@", error);
}];
這是我如何設置數據源:
extern NSString * const kClearDataSource;
@interface AHImageDataSource : NSObject
+ (AHImageDataSource *)sharedDataSource;
- (void) clearDataSource;
- (void) addObject:(id) object;
- (void) addObject:(id)object atIndex:(int) index;
- (int) count;
- (id) objectAtIndex:(int) index;
@end
NSString * const kClearDataSource = @"clearDataSource";
@interface AHImageDataSource()
{
NSMutableArray * imageDataSource_;
}
@property (nonatomic, retain) NSMutableArray * imageDataSource_;
@end
@implementation AHImageDataSource
@synthesize imageDataSource_;
+ (AHImageDataSource *)sharedDataSource {
static AHImageDataSource *_sharedClient = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] init];
});
return _sharedClient;
}
- (id)init {
self = [super init];
if (!self) {
return nil;
}
NSMutableArray * temp = [[NSMutableArray alloc] initWithCapacity:200];
self.imageDataSource_ = temp;
[temp release];
return self;
}
-(void) clearDataSource
{
if ([self.imageDataSource_ count] > 0){
[self.imageDataSource_ removeAllObjects];
}
}
- (void) addObject:(id) object
{
[self.imageDataSource_ addObject:object];
}
- (void) addObject:(id)object atIndex:(int) index
{
[self.imageDataSource_ insertObject:object atIndex:index];
}
- (int) count
{
return [self.imageDataSource_ count];
}
- (id) objectAtIndex:(int) index
{
if (index >= 0 && index < [self.imageDataSource_ count]){
return [self.imageDataSource_ objectAtIndex:index];
}
return nil;
}
- (void) dealloc
{
[super dealloc];
[imageDataSource_ release];
}
@end
編輯:
看來,NSZombieEnabled似乎隱藏了這個問題。當我禁用NSZombieEnabled時,它現在在模擬器和設備上崩潰。
如果NSZombieEnabled隱藏了這個問題,那麼它幾乎肯定是一個雙免費的。非常奇怪的儀器模板沒有拿起它... – MobileVet