在另一个ViewController中更改属性 [英] change a property in another 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屋!