我制作了一个用相机按钮拍照的测试应用程序。我在模拟器上测试,所以我不能拍快照。但是我已经创建了一个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];
}在上面的场景中,当方法被调用时(即当我点击相机栏按钮项时),控制台不会记录相机按钮点击的消息,以及呈现给Modal Controller message.All的其他适当的NSLog消息。我不明白为什么运行时不执行这些NSLog行。在-(void)imagePickerController:(UIImagePickerController *) 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和第三行--未在控制台中显示Modal Controller。同样,运行库不处理这些NSLog行。
我是不是想错了,因为这种行为太奇怪了。发生什么事了呢?
发布于 2013-12-19 11:48:38
请检查以下代码行:-
#define NSLog if(0) NSLog如果提到0,则nslog语句将不会执行。所以,让它1和检查
#define NSLog if(1) NSLog发布于 2013-12-19 12:19:35
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", \[ stringWithUTF8String:FUNCTION lastPathComponent],LINE,\ NSString stringWithFormat:(s),##VA_ARGS;
定义ALog(.) #endif
使用就像NSLog ex: ALog(@"log是放置的“);
https://stackoverflow.com/questions/20680713
复制相似问题