最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【已解决】iOS中,某个类(UIImagePickerController)的实例变量,找不到其某个方法(isSourceTypeAvailable)

iOS crifan 1284浏览 0评论

【问题】

在折腾

关于iOS/iPhone中的文件选择对话框,用于用户去选择图片等文件

过程中,遇到一个问题,参考UIImagePickerController Class Reference,去初始化了一个UIImagePickerController的实例变量,但是却无法试用其对应的某个方法isSourceTypeAvailable:

找不到isSourceTypeAvailable方法

 

【解决过程】

1.后来去参考了别人:iPhone利用UIImagePickerController调用系统照相机中的代码:

    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }   

看到是类本身UIImagePickerController去直接调用该函数的。

2.然后再回去看官网中的UIImagePickerController Class Reference对该函数的解释:

isSourceTypeAvailable:

Returns a Boolean value indicating whether the device supports picking media using the specified source type.

+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType

Parameters
sourceType

The source to use to pick an image or movie.

Return Value

YES if the device supports the specified source type; NO if the specified source type is not available.

Discussion

Because a media source may not be present or may be unavailable, devices may not always support all source types. For example, if you attempt to pick an image from the user’s library and the library is empty, this method returns NO. Similarly, if the camera is already in use, this method returns NO.

Before attempting to use an UIImagePickerController object to pick an image, you must call this method to ensure that the desired source type is available.

Availability
  • Available in iOS 2.0 and later.
See Also
Declared In

UIImagePickerController.h

可以看到函数前面是加号“+”而不是常见的减号“-”,对应的表示是Class本身的函数。

所以,此时才明白,此处UIImagePickerController的实例变量中,为何找不到方法isSourceTypeAvailable,因为其是属于类函数,而非实例函数。

3.所以,换做用Class本身再去调用该函数,就可以了:

can found isSourceTypeAvailable

 

【总结】

以后对于Class还是Instance类型的变量,需要注意一下了,否则就会出现这个基本的概念不清楚的问题,在实例中引用类的变量而找不到的问题了。

转载请注明:在路上 » 【已解决】iOS中,某个类(UIImagePickerController)的实例变量,找不到其某个方法(isSourceTypeAvailable)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
47 queries in 0.102 seconds, using 18.67MB memory