views:

249

answers:

3

Is it possibe to put an MPVolumeView in a UIAlertView?

I have tried to put it inside of it, but it does not display. It may be the sizeToFit or initWithFrame: part? Is there a way of testing if the MPVolumeView is actually being created?

Here's the code I initialize both the UIAlertView and MPVolumeView with:

UIAlertView *volumeAlert = [[UIAlertView alloc] initWithTitle:@"Volume" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:volumeAlert.bounds];

[volumeAlert addSubview:volumeView]; 

[volumeAlert sizeToFit];

[volumeAlert show];
[volumeAlert release];
[volumeView release];
+1  A: 

UIAlertView is a subclass of UIView, and UIView has a convenient addSubview: method. Have you tried that?

Dave DeLong
Yep. Added some code to main post.
Emil
@Emil ok.... so is your code working or not? if it's not, what's happening? what are you expecting to happen? are any errors being logged? you can't just say "here's my code, fix it for me"...
Dave DeLong
It is not working, the UIAlert pops up, but there is no volume slider there. Could it be the `initWithFrame:` part that's causing it? Do you know a way of testing if it even creates the volumeView?
Emil
A: 

You might like to check out this recent blog post from Jeff LaMarche, should fill your needs - Custom Alert Views

alku83
+1  A: 

I think initing the VolumeView with the VolumeAlert's frame would cause problems. Since VolumeAlert's frame is never being set (before VolumeView's frame is set), you can't depend on it being any size.

ACBurk
What size would I use for this purpose? I am really bad at creating and placing stuff in code/realtime..
Emil
I would just try something like CGRECTMAKE(0,0,100,20) to see if it show up at all to check to see if that is actually the cause. Though if I remember correctly from other things I have read, UIAlertView is not customizable (without private api's or rolling your own version), so this may all be for not.
ACBurk
I'll mark this as the accepted answer, because this is the most relevant answer. I do not use this solution afterall, see question.
Emil