我制作了一个使用相机按钮拍照的测试应用程序。我正在模拟器上测试,所以我无法拍摄快照。但是我已经创建了一个IBAction方法,当被调用时,允许用户从照片库中选择一张图片。 这是方法: -
- (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行。 在我面临的 - (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)
检查下面这行代码: -
#define NSLog if(0) NSLog
如果提到0,那么您的nslog语句将不会执行。所以将它设为1并检查
#define NSLog if(1) NSLog
答案 1 :(得分: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 ALog(...) #ENDIF
使用就像NSLog ex:ALog(@“log is put”);