Title for the UIAlertController is not appearing iOS 8.0 - ios

I have updated for XCode 6.0.1, iOS 8.0 and after that used UIAlertController instead of UIAlertView but Title for the UIAlertController is not appearing.
For Reference see code:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"AlertView" message:#"Please Click" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:defaultAction];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];

What you are presenting is actually an action sheet, which is not equivalent to the UIAlertView. You should change preferredStyle, use UIAlertControllerStyleAlert instead UIAlertControllerStyleActionSheet:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"AlertView" message:#"Please Click" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
Now, where are the buttons? You can add for example (before presentViewController):
[alert addAction:[UIAlertAction actionWithTitle:#"Ok" style:UIAlertActionStyleDefault handler:nil]];
And then create your action to implement the handler.

Related

How present UIMenuController and UIAlertController at the same time?

I'm trying next way:
Message *message = self.messagesArray[indexPath.row];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:LocalizedString(#"FirstAction")
message:#""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *editMessage = [UIAlertAction actionWithTitle:LocalizedString(#"SecondAction") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:editMessage];
UIAlertAction *forwardMessage = [UIAlertAction actionWithTitle:LocalizedString(#"ThirdAction") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:forwardMessage];
UIAlertAction *deleteMessage = [UIAlertAction actionWithTitle:LocalizedString(#"DeleteMessage") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:deleteMessage];
[self setSourceViewForAlertController:alertController];
[self presentViewController:alertController animated:YES completion:nil];
[self createMenuForMessage:message];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
So, my aim is to present alertcontroller for UICollectionViewCell and UIMenuController at the same time.
Like this:
Your issue is related to where are you showing your UIMenuController you have to take in account that UIView must have implemented the canBecomeFirstResponder method returning YES
- (IBAction)action:(id)sender {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#""
message:#""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *editMessage = [UIAlertAction actionWithTitle:#"Edit" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:editMessage];
UIAlertAction *forwardMessage = [UIAlertAction actionWithTitle:#"Move" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:forwardMessage];
UIAlertAction *deleteMessage = [UIAlertAction actionWithTitle:#"Delete" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alertController addAction:deleteMessage];
[self presentViewController:alertController animated:YES completion:nil];
[[UIMenuController sharedMenuController] setTargetRect:self.view.bounds inView:self.view];
[[UIMenuController sharedMenuController] setArrowDirection:UIMenuControllerArrowDefault];
[[UIMenuController sharedMenuController] setMenuItems:#[[[UIMenuItem alloc]initWithTitle:#"test" action:#selector(didReceiveMemoryWarning)]]];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
-(BOOL)canBecomeFirstResponder{
return true;
}

UIAlertView is deprecated : first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle

How to change this obj c code that suits with iOS 9 above ? i have this error when i updating X Code into 8.2.1 . The code as below
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Continue"]){
NSLog(#"Continue...");
[self performSegueWithIdentifier:#"createlogin" sender:self];
}
}
The error:
UIAlertView is deprecated : first deprecated in iOS 9.0 - UIAlertView
is deprecated. Use UIAlertController with a preferredStyle of
UIAlertControllerStyleAlert instead
Thanks.
UIAlertController * alert = [UIAlertController alertControllerWithTitle:#"Add Title" message:#"Add Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * actionOK = [UIAlertAction actionWithTitle:#"Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Here Add Your Action
}];
UIAlertAction * actionCANCEL = [UIAlertAction actionWithTitle:#"Second Button Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//Add Another Action
}];
[alert addAction:actionOK];
[alert addAction:actionCANCEL];
[self presentViewController:alert animated:YES completion:nil];
Use this Method if any need ask me and for more Information use this Link http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/
Use this code
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Title" message:#"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * continueButton = [UIAlertAction actionWithTitle:#"Continue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
[self performSegueWithIdentifier:#"createlogin" sender:self];
}];
UIAlertAction * cancelButton = [UIAlertAction actionWithTitle:#"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
}];
[alert addAction:continueButton];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
try this:
UIAlertController *controller = [UIAlertController alertControllerWithTitle:#"Your message title"
message:#"Enter your message here."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
{
NSLog(#"Ok Action");
}];
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:#"Skip" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
NSLog(#"Cancel Action");
}];
[controller addAction:okAction];
[controller addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];

UIAlertController + addTextField orientation issue from iOS10 on iPad

When I use UIAlertController with addTextField on iPad, the keyboard doesn't rotate properly from iOS10.
It was working fine with iOS9, does anybody know the way to fix it?
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:#"title"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *done = [UIAlertAction actionWithTitle:NSLocalizedString(#"Done", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
UITextField *textField = alert.textFields.firstObject;
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(#"Cancel", nil)
style:UIAlertActionStyleCancel
handler:nil];
[alert addAction:cancel];
[alert addAction:done];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
}];
[self presentViewController:alert animated:YES completion:nil];

How to fix default popup menu using uiactivityviewcontroller

I have problem, my app using default uiactivityviewcontroller, but it too big on iphone 6+. How to fix it ?
Button in my app too big
Button other app
My code
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[self presentViewController:mail animated:YES completion:NULL];
UIAlertController *actionSheet= [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *actionSheetDeleteDraft = [UIAlertAction
actionWithTitle:#"Delete Draft"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(#"Delete is pressed");
}];
UIAlertAction *actionSheetSaveDraft = [UIAlertAction
actionWithTitle:#"Save Draft"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(#"Save pressed");
}];
UIAlertAction *actionSheetCancel = [UIAlertAction
actionWithTitle:#"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action)
{
NSLog(#"Cancel pressed");
}];
[actionSheet addAction:actionSheetDeleteDraft];
[actionSheet addAction:actionSheetSaveDraft];
[actionSheet addAction:actionSheetCancel];
[self presentViewController:actionSheet animated:YES completion:nil];

Xcode Buttons: Some work, some do not?

I am attempting to design an app for my senior project, and am thus fairly new to iOS coding. I have created a .xib view controller, and added a number of buttons to it, over top of some card images. There is one large button over the other player's hand, and sever smaller ones over each of the player's own cards.
I have added UIAlertControllers to each button, intending the pop-ups to allow the player to play or discard their own cards, or send some information about the other player's.
The Alert pops up fine for the other player's button, but the ones for the bottom cards do absolutely nothing. I have checked that they are all connected to the IBActions, and the code is nearly identical to the button that IS working. Any ideas?
This is all contained within gameViewController.m: btnTop correctly performs its action, while btnBottom1 - btnBottom5 do nothing.
- (IBAction)btnTop:(id)sender{
NSLog(#"Top Button Pressed. Displaying AlertView.");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Give Information" message:#"Would you like to give information about color or number?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionColor = [UIAlertAction actionWithTitle:#"Color" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self giveColorInfo];
}];
UIAlertAction *actionNumber = [UIAlertAction actionWithTitle:#"Number" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:actionColor];
[alertController addAction:actionNumber];
[alertController addAction:actionCancel];
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)btnBottom1:(id)sender{
NSLog(#"Bottom 1 Button Pressed. Displaying AlertController.");
UIAlertController *alertController2 = [UIAlertController alertControllerWithTitle:#"Play or Discard Card 1" message:#"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:#"Play"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self playCard:1];
}];
UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:#"Discard" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alertController2 addAction:actionPlay];
[alertController2 addAction:actionDiscard];
[alertController2 addAction:actionCancel];
[self presentViewController:alertController2 animated:YES completion:nil];
}
- (IBAction)btnBottom2:(id)sender {
NSLog(#"Bottom 2 Button Pressed. Displaying AlertView.");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Play or Discard Card 2" message:#"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:#"Play"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self playCard:2];
}];
UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:#"Discard" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:actionPlay];
[alertController addAction:actionDiscard];
[alertController addAction:actionCancel];
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)btnBottom3:(id)sender {
NSLog(#"Bottom 3 Button Pressed. Displaying AlertView.");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Play or Discard Card 3" message:#"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:#"Play"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self playCard:3];
}];
UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:#"Discard" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:actionPlay];
[alertController addAction:actionDiscard];
[alertController addAction:actionCancel];
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)btnBottom4:(id)sender {
NSLog(#"Bottom 4 Button Pressed. Displaying AlertView.");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Play or Discard Card 4" message:#"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:#"Play"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self playCard:4];
}];
UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:#"Discard" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:actionPlay];
[alertController addAction:actionDiscard];
[alertController addAction:actionCancel];
[self presentViewController:alertController animated:YES completion:nil];
}
- (IBAction)btnBottom5:(id)sender {
NSLog(#"Bottom 5 Button Pressed. Displaying AlertView.");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:#"Play or Discard Card 5" message:#"Would you like to play or discard?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionPlay = [UIAlertAction actionWithTitle:#"Play"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
[self playCard:5];
}];
UIAlertAction *actionDiscard = [UIAlertAction actionWithTitle:#"Discard" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:actionPlay];
[alertController addAction:actionDiscard];
[alertController addAction:actionCancel];
[self presentViewController:alertController animated:YES completion:nil];
}

Resources