I wanted to use UIAlertView to show photo. I´m using code as below for showing the alert, however it doesn't work. It shows the title, some space and button OK nothing more. I have no idea if I´m doing something wrong, because I´m new in iOS.
-(IBAction)ButtonPressed:(id)sender
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"titel"
message:nil
delegate:nil //or self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(180, 10, 85, 50)];
[imageView setImage:#"dog.png"];
[av setValue:imageView forKey:#"accessoryView"];
[av show];
}
#Popeye is correct what he said : UIAlertView is meant to be used as-is and you shouldn't be messing with the view hierarchy this will get your app rejected from the Apple App review process. Please read Apple documentation regarding UIAlertViews. So you should NOT be using setValue: forKey:#"accessoryView" and/or addSubview:. Specific section below
Subclassing Notes
The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.
Solutions
1) Use 3 party such as CNPPopupController and many other available check this link
OR
2) create of your own.
Related
i want to do something like this : i want to prompt an alert view,but inside that alert view i want to add some labels,text fields and star marks[for rating].how can i do that in iOS.i am using iOS 7.and i am really new to this.i did this in my android application. but i don't know how to do that same thing in here.
in my application i am using storyboards.i had an idea about to design a customised view and load it inside alert view. but i do not know weather that can be done or not.please someone help me for this.
thank you.
Any CustomView can't be directly added to UIALertView.
For alertView there is one property "accesseryView".By Using this we can add any UIView to UIAlertView.
-(void)customAlertView{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:#"your Title" message:#"Your
Message" delegate:nil cancelButtonTitle:#"Your
Button Title" otherButtonTitles:nil];
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:#"MyCustomViewOnAlert" owner:self options:nil];
MyCustomViewOnAlert *myView = (MyCustomViewOnAlert*) [subviewArray objectAtIndex:0];
[Alert setValue:myView forKey:#"accessoryView"];
[Alert show];
}
One Custom View "MyCustomViewOnAlert" is created on XIB.
Try This
If you need library prompting user to rate your app in the App Store use this library
https://github.com/nicklockwood/iRate
I'm creating an app, and at one moment i want to ask the user opinion with a custom UIAlertView. After a lot of researches, and reading about this subject, i'm a little confused about some things...
What objects (UITextfields, UIImages...) could we add to an UIAlertView ?
Because i found this :
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
But this could have been accepted for example :
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"title" message:#"msg" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[alertView addSubview:txtField];
[alertView show];
[alertView release];
(See this link for more informations)
So for example, if i don't want the blue-box with message, and title parameters, could i only do this code :
UIAlertView *alert = [[UIAlertView alloc] init];
[alert addSubview:a_UIButton];
[alert addSubview:a_UIImageview];
[alert show];
So with this sort of code i could get the advantage (if it's work !) of put in pause mode all the app', and all would be custom. But is it possible ? Could it be reject ?
Thanks a lot !
Instead of trying to customize "UIAlertView", why not just create your own custom AlertView (from "UIView") and add that as a subview when you want to display it?
We don't know if (or how) Apple might change the internal architecture of UIAlertView in future versions of iOS (e.g. iOS 7) that would break all the various customizations done to it in all the apps that have gotten away with it so far. That's why Apple put up that warning in their documentation.
I would recommend instead that you make a custom UIView, and just display that with a similar animation to the UIAlertView. Then, you can add whatever UI elements you'd like. If the docs say the view hierarchy is private, I'd leave it alone.
If all you want to do is add a text field to the alert view, that functionality is supported in iOS 5 and later using:
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
I am trying to make a iPad application which information will popup inside the UINotification. But the default size of the notification is relatively small. Is there any way i can increase the size of the notification?
-(IBAction) player1:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Player1" message:#"Long message"delegate:self cancelButtonTitle:#"Done" otherButtonTitles:nil, nil];
[alert show];
}
I tried to add this code,
alert.frame = CGRectMake(0,0,500,500);
but the text inside does not follow.
Is there any way to solve this?
Thanks
You can't change an UIAlertView :( It's deliberately designed to force you to be brief!
If you want to display a large amount of data, your best option is to create a custom UIView and show that instead.
I am using the UIAlertView to show the text field over a popup. But the problem I am facing is that I am not able to validate and restrict the entries in UITextField over a popup, i.e. I want to accept only 3 numeric values.
Here i am providing the block of code that I have implemented.
popup = [[UIAlertView alloc] initWithTitle:#"Please enter 3 numeric values"
message:#"\n\n"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Ok", nil];
txtFld = [[UITextField alloc] initWithFrame:CGRectMake(12, 50, 260, 25)];
[txtFld setBackgroundColor:[UIColor whiteColor]];
[txtFld setKeyboardType:UIKeyboardTypeNumberPad];
[popup addSubview:txtFld];
[popup show];
[txtFld becomeFirstResponder];
So can anyone help me out to resolve this issue? Thanks in advance.
here I can see that you have not set textfield.delegate=self , please check it in your code
It is risky to manually add subviews to UIAlertView or any other view you do not control as its hierarchy is private and subject to change. If you're targeting iOS 5 or above, you can use one of the UIAlertView styles that supports text entry and validation such as UIAlertViewStylePlainTextInput. The documentation for UIAlertView provides a list of styles and this tutorial explains their use in more detail.
I am using Local Notifications, but I want to put an image in the message body of the alert. How can I do that?
I also searched for the same question. And found that we can't customize the UILocalNotification, so I handled this in application:didReceiveLocalNotification: by showing custom UIAlertView.
This should work. Give it a whirl:
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
UIImage *smiley= [UIImage imageNamed:#"smiley.png"];
[imageView setImage:smiley];
[smiley release];
[successAlert addSubview:imageView];
[imageView release];
[successAlert show];
[successAlert release];
Good luck,
Aurum Aquila
If you are using simple images like question mark, notification, etc. I suggest Ext JS which has a Icon type alert.
You can add your images as well.