I am experiencing an odd lag in the animation whenever I display a UIAlertView. The buttons and labels on the alert view are appearing noticeably before the background. It is happening everywhere in the application that I display an alert
The alert in the example above is shown from the action method of the clear button:
-(IBAction)clearButtonTapped:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Clear Outbox" message:#"This will delete everything from your Outbox." delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK",nil];
[alert show];
}
Does anyone know why this is happening / what I can do to stop it?
Set "renders with edge antialiasing" to NO in the info.plist
try this
[yourAlert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:NO];
Related
I have to fix some bugs in an old application and got a really weird one. All alert views are shown in the top left corner for some reason. App doesn't use storyboards, main window is loaded from xib. What can cause this?
UPDATE: Code to initialize alert view is pretty standard. I'm calling it inside one of the controllers of UITabBarController. Same bug occurs even if I leave app's main window empty and initialize alert view in application:didFinishLaunchingWithOptions:
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:#"Title"
message:#"Message"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[testAlert show];
I fixed this by simply replacing the [alert show] with the present [self presentViewController:alert animated:YES completion:nil];
I have a method called errorHandle which gives the alert view and I am calling this method in the #try block
-(void) errorHandle {
UIAlertView *disp = [[UIAlertView alloc] initWithTitle:#"Invalid QR Code" message:nil delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[disp show];
//[disp dismissWithClickedButtonIndex:0 animated:YES];
}
#try{
dispatch_async(dispatch_get_main_queue(), ^{
[self errorHandle];
});
}
Here I am getting the alert view but when I tap on the cancel button,the alert view is dismissing and appearing back again . I could not dismiss the alert view with single tap but after tapping several times the alert view is dismissed but the CPU usage during the operation boosted to 190%.
After the alert view is dismissed ,I again tried to get the alert view again I have to tap the cancel button several times. Is there anyway to dismiss the alert view properly on main thread and make it not to appear again?
I tried the following code but it didn't work out for me
1)
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"Event" message:#"Event added in calendar" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alertview performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:YES];
2)
__block UIAlertView *alert1 =[[UIAlertView alloc] initWithTitle:#"Event" message:#"Event added in calendar" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
dispatch_async(dispatch_get_main_queue(), ^(void){
[alert1 show];
});
Can we generate alert view in #finally block
is this possible?
#finally{
// alert view code
}
Can anyone answer me about these two issues?
The UIAlertView message doesn't show properly when the text field in it is being edited (when the keyboard is being displayed). Here's how it looks like:
When the keyboard isn't there:
This is the code that creates the alert view:
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Title"
message:#"Enter a name for your recipe"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
Is there a way to change the size of some components of the view so that it fits properly in the screen when the keyboard is displayed?
Edit: I just discovered that the alert view becomes scrollable when the keyboard appears. So if you scroll down, you can see the message. But I didn't notice that the first time the alert view popped up, and other users might not either. For now, I'm using what Visput suggested.
It is standard behavior for iOS. You could see the same layout in "Photos" application when create new Album in landscape mode.
I think the best way in this situation: place all text to message but title set to nil.
In your case:
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:nil
message:#"Title: Enter a name for your recipe"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
I'm working on a losing screen and I'd like to let users view their game before showing the stats screen. I've decided to use an alert to show users the current screen. After they hit OK, they should be taken to the stats screen.
The problem is, the stat screen pops up at the same time as the alert. How can I make sure the stats screen opens after the user closes the alert?
if ([self.model userHasLost]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry!" message:#"You lost..." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[self _showGameEndScreenWitnWin:NO]; //Stats screen should open after alert is closed
}
You need to use delegate method of UIAlertView and also need to set delegate of UIAlertView = self,
Following is delegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
check buttonIndex in this method it's give you NSInteger and manage click of button.
For more information read this UIAlertView Delegates.
You need to set the alert view delegate. In this example self will conform to the UIAlertViewDelegate protocol.
if ([self.model userHasLost]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sorry!" message:#"You lost..." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.delegate = self;
[alert show];
}
You can then listen to a delegate method for when the alert view is dismissed :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
[self _showGameEndScreenWitnWin:NO]; //Stats screen should open after alert is closed
}
For this situation need to use delegate method,
For simple Example Refer Here: http://www.idev101.com/code/User_Interface/UIAlertView.html
alert = [[UIAlertView alloc] initWithTitle:#"Enter Student Name" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Save", #"Save and Add", nil];
alert.tag = 1;
alert.alertViewStyle=UIAlertViewStylePlainTextInput;
[alert show];
its been working beautifully in potrait mode but in landscape my UITextfield going out of screen.and now i want to move a alertView frame a little bit down so that it will be visible .
Unfortunately you can't change any thing in the UIAlertView design in iOS7, you should use it as is, you have three chices here:
Take off the cancel button (If i were you i would do this).
Use a custom UIAlertView from cocoacontrols.com and put the three buttons at the same line.
Use another control like popover or modal.