我正在使用此代码显示图像,但我希望将该图像链接回rootView。有什么建议?

UIImage *image = [UIImage imageNamed: @"Invest.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage: image];

谢谢!

最佳答案

正如我在上面的评论中提到的,您可以使用NSNotification将其发布回rootView控制器:

YourViewController.m :(图像所在的视图控制器)

调用:[self yourMethod];将图像发布回rootView

- (void)yourMethod
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"postImage" object:self.yourImage userInfo:nil];
}

RootViewController.m:

在这里,我们需要添加一个观察者,以便以后可以从应用程序的其他部分接收要发布的图像。
- (void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postedImage:) name:@"postImage" object:nil];
}

在这里,我们将通知的对象作为postsImage:
- (void)postedImage:(NSNotification *)notification
{
    UIImage *postedImage = notification.object;
}

不要忘记使用dealloc方法删除观察者!
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

关于ios - 顶部栏-UIImage链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22669341/

10-13 04:03