在另一个ViewController中更改属性 [英] change a property in another viewcontroller

查看:70
本文介绍了在另一个ViewController中更改属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了如何在stackoverflow上从另一个ViewController运行方法,但没有找到答案. 我有一个ViewController1使用AVAudioPlayer播放音频,我希望我的ViewController2能够更改其音量.

I've searched how to run a method from another ViewController on stackoverflow and didn't find an answer. I have a ViewController1 playing an audio using AVAudioPlayer and I want my ViewController2 to be able to change it's volume.

我尝试了以下基本操作:在ViewController2中调用一个方法来更改ViewController1中的音量.
这是行不通的.该方法可以输出日志,但不能更改属性.

I've tried the basic: calling a method in ViewController2 that changes the volume in ViewController1.
This doesn't work. The method is able do output Logs but isn't able to change properties.

谢谢

推荐答案

您需要将消息从ViewController2传递到ViewController1.
为此,请使用:
1.通知
2.委派

You need to pass a message from ViewController2 to ViewController1.
For that either use:
1. Notifications
2. Delegation

如果您不知道这两个教程,则这里是本教程的链接.
http://devinsheaven.com/对象通知之间的可可教程传递消息-代理和目标动作/

Here is the link for a tutorial if you are unaware of both of them.
http://devinsheaven.com/cocoa-tutorial-passing-messages-between-objects-notifications-delegates-and-target-action/

这篇关于在另一个ViewController中更改属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆