Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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
C# Xamarin Studio:将UIimageView添加到UIView_C#_Ios_Xamarin.ios_Xamarin_Xamarin Studio - Fatal编程技术网

C# Xamarin Studio:将UIimageView添加到UIView

C# Xamarin Studio:将UIimageView添加到UIView,c#,ios,xamarin.ios,xamarin,xamarin-studio,C#,Ios,Xamarin.ios,Xamarin,Xamarin Studio,我想将imageview添加到我的视图中,但该图像未显示。 我的代码怎么了?谢谢你的帮助 ...Constructor(UIImage _pickedImage...... UIImageView iv = new UIImageView (this.Bounds); iv.Image = this.pickedImage; this.AddSubview (iv); iv.Release (); 您的代码片段相当短,但您应该而不是调用iv.Release()因为您将不平衡本机(ObjC)

我想将imageview添加到我的视图中,但该图像未显示。 我的代码怎么了?谢谢你的帮助

 ...Constructor(UIImage _pickedImage......

UIImageView iv = new UIImageView (this.Bounds);
iv.Image = this.pickedImage;
this.AddSubview (iv);
iv.Release ();

您的代码片段相当短,但您应该而不是调用
iv.Release()因为您将不平衡本机(ObjC)
UIImageView
实例的引用计数


事实上,您几乎不必自己调用此方法,因为Xamarin.iOS有一个垃圾收集器(GC),它在处理对象时会自动调用
释放
选择器(就像创建托管实例时会执行
保留
),发现这个问题在如何解决上还没有正确的答案。因此,为了将来的参考,我将解释我是如何解决它的

我循环浏览包含图像的列表,这些图像被描述为
。 首先,创建UIImageView

UIImageView imageView = new UIImageView();
然后获取图像的字节数组,并将其转换为UIImage

UIImage image = Utilities.ToImage(item.ImageBytesArray);
然后,使用UIImage设置UIImageView

imageView.Image = image;
接下来是什么解决了我的主要问题,没有出现。因此,我们将获得屏幕大小并将其存储在
screen

var screen = UIScreen.MainScreen.Bounds;
设置UIImageView的框架。这将创建可以看到的UIImageView。为了不与其他内容重叠,我的顶部偏移量必须为400。
CGRect(xOffset,yOffset,width,height)

我使用滚动视图,所以我将其添加到滚动视图中。也可以是此

scrollView.Add(imageView);
UIImageView=新UIImageView()
UIImage=Utilities.ToImage(item.ImageBytesArray)
Image=Image
var screen=UIScreen.MainScreen.Bounds
imageView.Frame=newcoregraphics.CGRect(0400,screen.Size.Width,300)
添加(图像视图)

scrollView.Add(imageView);