【发布时间】:2014-01-07 23:07:24
【问题描述】:
我制作了一个使用相机按钮拍照的测试应用。我正在模拟器上进行测试,所以我无法拍摄快照。但是我创建了一个 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控制器 消息。所有其他适当的 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 called 和倒数第三行 - Dismissing Modal Controller 未显示在控制台中。同样,运行时不会处理这些 NSLog 行。
我假设有什么问题吗,因为这种行为非常奇怪。发生了什么事?
【问题讨论】:
-
这听起来像是一个派生数据问题。尝试删除您的派生数据并进行干净的构建
-
派生数据到底是什么??
-
删除该特定文件夹的内容是否安全?它会做什么?
-
除了 NSLog .. 您的应用功能是否正常工作?像 NSLog (in editoe)、PO(Console)、P(Console) 之类的一些语句有时会不起作用,有时这些也会显示错误的值。功能工作正常,然后尝试显示警报而不是 NSLog 并检查。
-
派生数据是您项目的索引信息。删除它会强制 XCode 重新索引您的项目。
标签: ios objective-c cocoa-touch cocoa