简体   繁体   English

如何从其他View控制器获取图像

[英]How to Get Image from other View controller

i have 2 views. 我有2个意见。 A button and an UIimageView in view 1. In view 2 i have table view with a list of categories and i have set up images for every category using: 视图1中的一个按钮和一个UIimageView。在视图2中,我具有带有类别列表的表格视图,并且使用以下命令为每个类别设置了图像:

cell.imageView.image

now if i select a row, i should see an enlarged image of that row in view 1. How can I accomplish this? 现在,如果我选择一行,则应该在视图1中看到该行的放大图像。我该如何做到这一点?

Use delegate methods. 使用委托方法。 Once a row is selected in second view, pass the UIImage object or image name and set it to the imageview in first view. 在第二个视图中选择一行后,传递UIImage对象或图像名称并将其设置为第一个视图中的imageview。

For more info on delegate methods, pl. 有关委托方法的更多信息,请参见。 see the following links. 请参阅以下链接。

The Basics of Protocols and Delegates 协议和代表的基础

Using Protocols and Delegates to pass data between views 使用协议和委托在视图之间传递数据

You can use an object in Application Delegate: 您可以在“应用程序委托”中使用对象:

UIImage* currentImage;

Now propertise and synthesize the object. 现在调整并合成对象。

Now when you are in the View2 and the cell is selected, assign the UIImage into the appDelegate's object: 现在,当您进入View2并选择了单元格时,将UIImage分配到appDelegate的对象中:

appDelegate.currentImage = img;      // Hope you have an array which contains the images 
                                     // which are displayed in the UITableViewCell

Then when View2 gets dismissed, call a notification to View1 and in that notification method, assign the image to the UIImageView object of View1: 然后,当View2被关闭时,调用View1的通知,并在该通知方法中,将图像分配给View1的UIImageView对象:

imageview.image = appDelegate.currentImage;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从视图控制器移动到其他视图控制器在故事板编程 - How to move from a view controller into other view controller in storyboard programmatically 如何从一个视图控制器导航到另一个 - How to navigate From one view controller to other 如何从其他视图控制器调用xcode视图控制器 - how to call xcode view controller from other view controler 如何从导航控制器中的viewcontrollers堆栈中获取特定的视图控制器? - How to get a particular view controller from the stack of viewcontrollers in the navigation controller? 如何在导航控制器中将数据从一个视图传递到另一个视图 - How to pass data from one view to the other in a navigation controller 如何将值从其他视图控制器到iPhone中的自定义UIView - how to assing values from other view controller to custom UIView in iphone 将渐变颜色从一个视图控制器传递到另一个视图控制器 - Pass Gradient Color from one view controller to other view controller 如何使用segue将图像从视图控制器传递到选项卡栏? - how to pass image from view controller to tab bar with segue? 如何使用setmathod从一个视图控制器从另一个视图控制器获取uitextfield文本 - how to get uitextfield text from one view controller from another view controller using setmathod 从另一个View Controller Swift 2.0更改View Controller图像 - Change View Controller Image from another View Controller Swift 2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM