UIAlertView is not positioned at the center of the screen - ios

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

Related

Integrate with Chartboost objective-c

I've successfully integrated Chartboost rewarded video, it works but i want to implement the code that will increase credits when a user has completely watched a rewarded video. I've tried to implement in app delegate and it works calling it but due to some internal functions i will need to implement in specific view controller. so when i put the same code
-(void)didCompleteRewardedVideo:(CBLocation)location
withReward:(int)reward {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Really reset?" message:#"hi ?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
// optional - add more buttons:
[alert addButtonWithTitle:#"Yes"];
[alert show];
}
the alert view will not appear if i implement this code in specific view controller instead of appdelegate. i assume it is not called in view controller since it has no response. i need help to implement in view controller
In order to make UI changes, you should call it on main queue.
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Really reset?" message:#"hi ?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
// optional - add more buttons:
[alert addButtonWithTitle:#"Yes"];
[alert show];
});
Or you can just pass the delegate of the view and show the alert on it.
-(void) DisplayMessage:(NSString*)message withDelegate:(id)delegate
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Title"
message:message delegate:delegate
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[alert show];
}

UIAlertView animation lag when shown

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

UIAlertView message doesn't display properly when keyboard is displayed

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

Adding View Controller's view to UIAlertView (Objective c)

I have ViewController with UITableView. if i touch on any Cell, it shows information about this Cell in another view. It is working well. But when i add MyViewController's view to UIAlerView's view, if i touch on AlertView, it is giving runtime error.
this is my code:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
MyViewController *VC = [[MyViewController alloc] init];
[alert setValue:VC.view forKey:#"accessoryView"];
[alert show];
any help please ...
my program shows like this:
An alert view is simply shown on the screen. It doesn't matter which view controller is currently visible, when the show method is called, the alert view is added as the top view.
The only thing that would matter in terms of view controllers is which one you want as the delegate view controller, which can be assigned to objects other than self.
Refactor your code to look like this:
MyViewController *VC = [[MyViewController alloc] init];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"" delegate:VC cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
Notice how the VC you want to display is now the delegate to the alert?

Move UIAlertView litle bit down in landscape mode in ios 7

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.

Resources