设置从 ViewController 传递的 UIImage
我目前正在学习如何在 Objective-C / Cocoa Touch 中工作,我确信这是一个非常简单的问题......
我有一个带有数组 imageList 的 ViewController,我将所选图像名称传递给nextController
[nextController newimg:[imagesList objectAtIndex:indexPath.row]];
在 nextController 中,我有一个 UIImageView,它设置了一个覆盖图像,但我不知道如何设置它,使其在那里可用。
UIImageView *myImage;
-(void)viewDidLoad{.....
myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", (NSString *)currentImage]];
[myImage setImage:image];
我需要弄清楚如何将“currentImage”设置为从另一个 ViewController 传递的值。
我可以设置图像名称,它将通过 NSLog 显示,但在 viewDidLoad 中不可用。
- (void)newimg:(NSString *)_text;
{
NSString *img = (NSString *)_text;
}
如果有人能指出我正确的方向,我将不胜感激。
蒂亚!
I am currently learning how to work in Objective-C / Cocoa Touch and I am stuck with what I'm sure is a very simple problem....
I have a ViewController with an array imageList from where I pass the selected image name to the nextController
[nextController newimg:[imagesList objectAtIndex:indexPath.row]];
In nextController I have an UIImageView that sets up an overlay image and I can't figure out how to set it that it's availeable there.
UIImageView *myImage;
-(void)viewDidLoad{.....
myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", (NSString *)currentImage]];
[myImage setImage:image];
I need to figure out how to set "currentImage" to the value passed from the other ViewController.
I can set the image Name and it will show with NSLog but it will not be available in viewDidLoad.
- (void)newimg:(NSString *)_text;
{
NSString *img = (NSString *)_text;
}
I would greatly appreciate if someone can point me in the right direction.
TIA!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必在 viewDidLoad 中初始化 UIImageView,您可以在设置图像名称的 setter 函数中执行此操作。
另一种选择是在显示视图之前设置图像名称,这样您就可以在调用 viewDidLoad 之前设置图像名称。
You don't have to initialize UIImageView in viewDidLoad, you can do this in the setter function where you set the imagename.
Another option is to set the image name before showing the view, this way you will have the imagename set before viewDidLoad is called.