customised alert view for asking user comments and rates - ios

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

Related

iOS UIAlertView with photo

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.

Tracking which UIAlert button is clicked to change UILabel

I'm a complete beginner and looking to learn how to start coding to build my own apps.
I've been messing around with the classic "Hello World" design and trying to improve on it based on the limited knowledge i have managed to gather in the past week but i've got stuck and hope someone can help me out!
So far I have a UITextField for the user to enter their name, a label to display their name and a button to update the display. To help understand UIAlertViews better I have also included a Alert if the name entered is Chris (or chris) and another alert if the name entered is not Chris. All this is functioning fine so far.
I'm looking to track what button is pressed on my incorrectName UIAlertView and then update my UILabel to say "Chris" if they click the "I Want to be Called Chris" button. I have build another app similar to this before from a tutorial and I have copied across the code which i thought should function the same but it doesnt seem to work.
Here is my .m file so far
#import "Solo1ViewController.h"
#interface Solo1ViewController ()
#end
#implementation Solo1ViewController
#synthesize setMessage;
#synthesize userName;
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle=([alertView buttonTitleAtIndex:buttonIndex]);
if ([buttonTitle isEqualToString:#"I Want To Be Called Chris!"])
{setMessage.text=#"Chris";}
}
-(IBAction)showMessage:(id)sender
{
setMessage.text=userName.text;
if ([userName.text isEqual:#"Chris"] || [userName.text isEqual:#"chris"])
{
UIAlertView *correctName;
correctName = [[UIAlertView alloc]initWithTitle:#":)" message:#"Great Name!" delegate:nil cancelButtonTitle:#"Bye Fellow Chris" otherButtonTitles:nil, nil];
[correctName show];
}
else
{
UIAlertView *incorrectName;
incorrectName=[[UIAlertView alloc] initWithTitle:#":(" message:#"Chris is a Better Name" delegate:nil cancelButtonTitle:#"No, Thanks" otherButtonTitles:#"I Want To Be Called Chris!", nil];
[incorrectName show];
}
}
-(IBAction)removeKeyboard:(id)sender{
[userName resignFirstResponder];
}
To me it seems as though this should work but I guess I'm probably missing something glaringly obvious or i'm doing it totally wrong.
Make sure to set the alert view's delegate to self! Right now you have the delegate set as nil.
Example:
incorrectName=[[UIAlertView alloc] initWithTitle:#":(" message:#"Chris is a Better Name" delegate:self cancelButtonTitle:#"No, Thanks" otherButtonTitles:#"I Want To Be Called Chris!", nil];

UIAlertView button text does not display

I'm attempting to get a simple alert message to display in my app. I am using the code recommended by Apple, but every time the Cancel button displays without its text. I don't believe I have any other code that could override the default display of the alert.
Screenshot can be seen here.
Here's my code to display the alert:
NSString *alertMessage = [NSString stringWithFormat:#"No results found for '%#'.", #"TEST"];
UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:#"Search Error"
message:alertMessage
delegate:nil
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil];
[theAlert show];
When I use NSLog(#"%#", [theAlert buttonTitleAtIndex:0]); to log the title, it outputs "Cancel" just fine.
I want to comment, but I have low reputation for it... Anyway, I had simmilar issue with UIButton, and I figured out, it was bug in Xcode 6. Have you tried Xcode 5?

Ask user opinion, with custom UIAlertView, what's the limit to be approved?

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];

Increase UIAlertView size on iPad

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.

Resources