Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何测试空UIImageView?_Iphone_Ios - Fatal编程技术网

Iphone 如何测试空UIImageView?

Iphone 如何测试空UIImageView?,iphone,ios,Iphone,Ios,我有以下代码,我想看看是否设置了特定的UIImageView(图像)。如果不是,那么我想显示一条错误消息 if (image==nil) { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"No Image Selected" delegate:nil

我有以下代码,我想看看是否设置了特定的
UIImageView
(图像)。如果不是,那么我想显示一条错误消息

if (image==nil) {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"No Image Selected" 
                                                                 delegate:nil 
                                                        cancelButtonTitle:@"OK" 
                                                   destructiveButtonTitle:nil 
                                                        otherButtonTitles:nil];

        [actionSheet showInView:[[self view]window]];
        [actionSheet autorelease];
    }

imageView.image==nil
?或者,要检查空图像,
CGSizeEqualToSize(imageView.image.size,CGSizeZero)

可能很难确定
(UIImageView*)图像是否已用图像初始化。您可能需要检查图像属性:

if (image.image == nil)
这适用于
image.image==nil
UIImageView
未设置图像初始化)和
image==nil
(因为发送到nil
的消息返回nil
)的情况


还要注意局部变量:仅仅因为您从不
alloc/init
image,并不意味着它将为零。

空图像示例是一个额外的优点。:)根本没有imageView.image方法。如果“imageView”是uiimage,而不是uiimageview,则可能没有imageView.image