I have a AVAudioPlayer property in my viewController and I want to draw a circle in my custom uiview if the music is playing.
in my MyViewController.h:
@property (strong, nonatomic) AVAudioPlayer *audio;
in my view.h
- (void) drawCircle
{
//DRAW Circle
}
now i want to check in my View.m if the audio is playing.
i tried to add the following in my View.h
@property (nonatomic, assign) MyViewController *ViewController_audio;
and then do if ([ViewController_audio _audio].playing) { }
in
but it didn't work.
Your syntax is wrong. Get rid of the underscore:
if ([ViewController_audio audio].playing)
or
if (ViewController_audio.audio.playing)
Either syntax is valid.
PS "...it didn't work" is supremely unhelpful. Always explain what happens. In your case, I'm assuming that you got a compiler error. So copy and paste the full text of the compiler error, and explicitly tell the line on which it occurs.
A view should not have a reference to view controller. This is a bad design. Instead you should have a flag in view which will be set by your view controller when its playing. The view will read this property & take ui decisions.
From design prospective i would suggest that no decisions should be left to view. It is view controller who has right to think, a view should only display.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.