2013-12-19 79 views
0

我做了一個測試應用程序,使用相機按鈕拍照。我正在模擬器上測試,所以我無法拍攝快照。但是我創建了一個IBAction方法,在調用時允許用戶從照片庫中選擇一張照片。 這是該方法: -NSLog不執行

- (IBAction)takePicture:(id)sender { 
      NSLog(@"Camera button tapped"); 
      UIImagePickerController *imagePicker= [[UIImagePickerController alloc] init]; 
       if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
        NSLog(@"Yes. The Camera is available"); 
        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; 

       } 
       else{ 
       NSLog(@"The Camera isn't available. Try thru the Photo Library"); 
       [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 
       } 
      imagePicker.allowsEditing=YES; 
      [imagePicker setDelegate:self]; 

      NSLog(@"Presenting Modal Controller"); 
      [self presentViewController:imagePicker animated:YES completion:NULL]; 

     } 

在上述情況下,當方法被調用(即當我點按相機欄按鈕項),控制檯不記錄照相機按鈕抽頭消息以及作爲呈現模態控制器 message.All其他適當的NSLog消息正在被記錄,因爲它們應該是。 我不明白爲什麼運行時不執行這些NSLog行。 在有一個類似的問題 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info我面對。 這裏的實施 -

 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
      NSLog(@"imagePicker called"); 
      NSString *oldKey= _item.imageKey; 
      if (oldKey) { 
       NSLog(@"Deleting image having key- %@",oldKey); 
       [[BNRImageStore sharedStore] deleteImageForKey:oldKey]; 
      } 

      UIImage *image= [info objectForKey:UIImagePickerControllerEditedImage]; 

      CFUUIDRef newUniqueID= CFUUIDCreate(kCFAllocatorDefault); 
      CFStringRef newUniqueIDString= CFUUIDCreateString(kCFAllocatorDefault, newUniqueID); 

      //Use that uniqueID to set our item's imageKey 
      NSString *key= (__bridge NSString *)newUniqueIDString; 
      _item.imageKey=key; 

      //Store image in the BNRImageStore with this key 
      NSLog(@"putting %@ in dictionary table",_item.imageKey); 
      [[BNRImageStore sharedStore] setImage:image forKey:_item.imageKey]; 

      //Releasing Core-Foundation objects 
      CFRelease(newUniqueIDString); 
      CFRelease(newUniqueID); 

      [imageView setImage:image]; 
      NSLog(@"Dismissing Modal Controller"); 
      [self dismissViewControllerAnimated:YES completion:NULL]; 
    } 

這裏。 NSLog消息-imagePicker調用並在第三個最後一行解除模式控制器沒有顯示在控制檯中。運行時不再處理這些NSLog行。

我假設有什麼問題,因爲這種行爲非常奇怪。發生了什麼?

+0

這聽起來像是派生的數據問題。嘗試刪除您的派生數據並做一個乾淨的構建 –

+0

究竟是一個派生數據? – rahulbsb

+0

刪除特定文件夾的內容是否安全?它會做什麼? – rahulbsb

回答

0

檢查這行代碼如下: -

#define NSLog if(0) NSLog 

如果是提0,則您的NSLog語句不會執行。因此,使它1,檢查

#define NSLog if(1) NSLog 
0
other than NSLog .. is your app functionality working fine? few statements like NSLog (in editoe), PO(Console), P(Console) will not work some time, some time these will show wrong values also. functionality is working fine then try to show alert instead of NSLog and check. 

嘗試使用的,而不是NSLog的檢查。

#ifdef DEBUG 
#define ALog(s, ...) NSLog(@"\n\n************************ DEBUG ***********************\n Class&method: %@,\n Line of Code: %d\n element Info: %@\n******************************************************************\n\n", \ 

[[NSString的stringWithUTF8String:FUNCTION] lastPathComponent],LINE,\ [NSString的stringWithFormat:(S),## VA_ARGS]);

的#else 的#define考勤記錄(...) #ENDIF

使用一樣的NSLog例如:考勤記錄(@ 「日誌放在」);