我做了一个测试应用程序,使用相机按钮拍照 . 我正在模拟器上测试,所以我无法拍摄快照 . 但是我创建了一个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];
}
在上面的场景中,当调用该方法时(即当我点击相机栏按钮项时),控制台不会记录 Camera button tapped 消息以及 Presenting Modal Controller 消息 . 所有其他适当的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 called 和第三行-- Dismissing Modal Controller 未显示在控制台中 . 同样,运行时不会处理这些NSLog行 .
我假设有什么不对劲,因为这种行为非常奇怪 . 发生了什么?
2 回答
检查下面这行代码: -
如果提到0,那么您的nslog语句将不会执行 . 所以把它做1并检查
尝试使用而不是NSLog并检查 .
[[NSString stringWithUTF8String: FUNCTION ] lastPathComponent], LINE ,\ [NSString stringWithFormat:(s),## VA_ARGS ]);
#else #define ALog(...)#endif
使用就像NSLog ex:ALog(@“log is placed”);