Ios NSLog未执行
我制作了一个使用相机按钮拍照的测试应用程序。我在模拟器上测试,所以我不能拍快照。但是我创建了一个iAction方法,当调用它时,允许用户从照片库中选择一张图片。 方法如下:-Ios NSLog未执行,ios,objective-c,cocoa-touch,cocoa,Ios,Objective C,Cocoa Touch,Cocoa,我制作了一个使用相机按钮拍照的测试应用程序。我在模拟器上测试,所以我不能拍快照。但是我创建了一个iAction方法,当调用它时,允许用户从照片库中选择一张图片。 方法如下:- - (IBAction)takePicture:(id)sender { NSLog(@"Camera button tapped"); UIImagePickerController *imagePicker= [[UIImagePickerController all
- (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];
}
在上述场景中,当调用该方法时,即当我点击摄像头栏按钮项时,控制台不会记录摄像头按钮点击消息以及显示模态控制器消息。所有其他适当的NSLog消息都会按其应有的方式记录。
我不明白为什么运行时不执行这些NSLog行。
在-voidimagePickerController中也存在类似的问题:UIImagePickerController*picker没有使用我面临的信息:NSDictionary*信息完成对媒体的访问。
下面是实现-
-(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行
我是不是想错了,因为这种行为太奇怪了。发生了什么事?检查下面这行代码:-
#define NSLog if(0) NSLog
如果为0,则不会执行nslog语句。因此,将其设为1并检查
#define NSLog if(1) NSLog
尝试使用而不是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],第行\
[NSString stringWithFormat:s,VA_ARGS]
否则
定义ALog。。。
恩迪夫
与NSLog ex一样使用:ALog@log被放置 这听起来像是一个衍生数据问题。尝试删除您的派生数据并进行清理构建派生数据到底是什么?删除特定文件夹的内容是否安全??它会做什么?除了NSLog。。你的应用程序功能正常吗?像editoe中的NSLog、POConsole、PConsole这样的语句很少有一段时间不起作用,有时它们也会显示错误的值。功能正常,然后尝试显示警报而不是NSLog并检查。派生数据是项目的索引信息。删除它会强制XCode重新编制项目索引。
#ifdef DEBUG
#define ALog( s, ... ) NSLog( @"\n\n************************ DEBUG ***********************\n Class&method: %@,\n Line of Code: %d\n element Info: %@\n******************************************************************\n\n", \