Myaaoonn
Myaaoonn

Reputation: 997

UIAlertView title does not display

I have created an alert as follows

UIAlertView *alert1 = [[UIAlertView alloc]
                           initWithTitle:@"Title"
                           message:@"message"
                           delegate:self
                           cancelButtonTitle:@"Cancel"
                           otherButtonTitles:nil];

 [alert1 show];

enter image description here

But it does not display the title. How can I fix this?

Upvotes: 0

Views: 1693

Answers (5)

Myaaoonn
Myaaoonn

Reputation: 997

I have just removed the following method from my ViewController category class and it's working fine!

- (void)setTitle:(NSString *)title
{
   // My Code
}

Upvotes: 1

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

I try in Xcode 5.1.1 in your code is working fine in my Xcode, see the output

enter image description here

and i also try in Xcode 6.0.1 your code is working fine in my Xcode, see the output

enter image description here

if u r using in Xcode 6.0.1 in swift

UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead.

UIAlertController * alert1 = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* aaction = [UIAlertAction actionWithTitle:@"okay" style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction * action) {
                                                      [alert1 dismissViewControllerAnimated:YES completion:nil];
                                                  }];
[alert1 addAction:aaction];
[self presentViewController:alert1 animated:YES completion:nil];

another choice

 let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert)

    let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
    alertController.addAction(defaultAction)

    presentViewController(alertController, animated: true, completion: nil)

need more help use this link http://www.appcoda.com/uialertcontroller-swift-closures-enum/

Upvotes: 2

Vidhyanand
Vidhyanand

Reputation: 5369

You can use following code using UIAlerController for XCode 6 and IOS 8

UIAlertController * alert=   [UIAlertController
                                 alertControllerWithTitle:@"Title"
                                 message:@"Your Message"
                                 preferredStyle:UIAlertControllerStyleAlert];

   UIAlertAction* ok = [UIAlertAction
                        actionWithTitle:@"OK"
                        style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction * action)
                        {
                            [alert dismissViewControllerAnimated:YES completion:nil];

                        }];
   UIAlertAction* cancel = [UIAlertAction
                            actionWithTitle:@"Cancel"
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction * action)
                           {
                               [alert dismissViewControllerAnimated:YES completion:nil];

                           }];

   [alert addAction:ok];
   [alert addAction:cancel];

   [self presentViewController:alert animated:YES completion:nil];

Hope it is useful to you..

Upvotes: 0

Deepak
Deepak

Reputation: 1441

Try this for iOS 8

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView" message:@"I am an AlertView" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction * action) {
                                                          [alert dismissViewControllerAnimated:YES completion:nil];
                                                      }];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];

Upvotes: 1

LS_
LS_

Reputation: 7129

From Xcode 6.0 UIAlertView class:

UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead.

On swift ( iOS 8 and OS X 10.10 ), you can do this:

var alert = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Cancel, handler:handleCancel))
        alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in
                println("User click Ok button")
            }))
        self.presentViewController(alert, animated: true, completion: nil)

func handleCancel(alertView: UIAlertAction!)
        {
            println("User click cancel button")
        }

Upvotes: 0

Related Questions