首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSLog不执行

NSLog不执行
EN

Stack Overflow用户
提问于 2013-12-19 11:35:47
回答 2查看 206关注 0票数 0

我制作了一个用相机按钮拍照的测试应用程序。我在模拟器上测试,所以我不能拍快照。但是我已经创建了一个IBAction方法,当调用它时,允许用户从照片库中选择一个图片。这就是方法:-

代码语言:javascript
复制
   - (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];

         }

在上面的场景中,当方法被调用时(即当我点击相机栏按钮项时),控制台不会记录相机按钮点击的消息,以及呈现给Modal Controller message.All的其他适当的NSLog消息。我不明白为什么运行时不执行这些NSLog行。在-(void)imagePickerController:(UIImagePickerController *) didFinishPickingMediaWithInfo:(NSDictionary *)info中也存在类似的问题。这是实施方案-

代码语言:javascript
复制
     -(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和第三行--未在控制台中显示Modal Controller。同样,运行库不处理这些NSLog行。

我是不是想错了,因为这种行为太奇怪了。发生什么事了呢?

EN

回答 2

Stack Overflow用户

发布于 2013-12-19 11:48:38

请检查以下代码行:-

代码语言:javascript
复制
#define NSLog if(0) NSLog

如果提到0,则nslog语句将不会执行。所以,让它1和检查

代码语言:javascript
复制
#define NSLog if(1) NSLog
票数 0
EN

Stack Overflow用户

发布于 2013-12-19 12:19:35

代码语言:javascript
复制
 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并检查。

代码语言:javascript
复制
#ifdef DEBUG
#define ALog( s, ... ) NSLog( @"\n\n************************ DEBUG ***********************\n Class&method: %@,\n Line of Code: %d\n element Info: %@\n******************************************************************\n\n",  \

[ stringWithUTF8String:FUNCTION lastPathComponent],LINE,\ NSString stringWithFormat:(s),##VA_ARGS

定义ALog(.) #endif

使用就像NSLog ex: ALog(@"log是放置的“);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20680713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档