Adding MPVolumeview programmatically in app

此生再无相见时 提交于 2019-12-12 21:01:44

问题


Trying to add MPVolumeView programmtically in app by using the following code

 MPVolumeView *_volumeView = [ [MPVolumeView alloc] init];
[_volumeView setShowsVolumeSlider:YES];
[_volumeView setShowsRouteButton:YES];
[_volumeView sizeToFit];
[view addSubview:_volumeView];

but getting so many Semantic issue that use of undeclared identifier MPVolumeView and Invalid operands to binary expression

@property (nonatomic, strong) MPVolumeView *volumeView;

Getting message in red for the above statement that unknown type MPVolumeView and plus property with retain or strong must be of object type.

 @synthesize volumeView = _volumeView;

Is this the right way to add MPVolumeView programmatically in app.

Thanks for help.


回答1:


MPVolumeView is part of the MediaPlayer framework. Did you include this in your application and did you #import <MediaPlayer/MediaPlayer.h> in your .m or .h file?

Also, if you declared a property, you should create a new local variable _volumeView. Replace the first line with this:

_volumeView = [ [MPVolumeView alloc] init];


来源:https://stackoverflow.com/questions/12236636/adding-mpvolumeview-programmatically-in-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!