UIAlertView标题不显示

我已经创build了如下的警报

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

在这里输入图像说明

但它不显示标题。 我怎样才能解决这个问题?

我尝试在Xcode 5.1.1中的代码在我的Xcode中正常工作,请参阅输出

在这里输入图像说明

我也尝试在Xcode 6.0.1你的代码在我的Xcode中正常工作,看到输出

在这里输入图像说明

如果你在Xcode 6.0.1swift

UIAlertView已被弃用。 相反,使用UIAlertController和UIAlertControllerStyleAlert的preferredStyle。

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

另一种select

  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) 

需要更多的帮助使用此链接http://www.appcoda.com/uialertcontroller-swift-closures-enum/

试试这个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]; 

我刚刚从我的ViewController类别类中删除了以下方法,它工作正常!

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

来自Xcode 6.0 UIAlertView类:

UIAlertView已被弃用。 相反,使用UIAlertController和UIAlertControllerStyleAlert的preferredStyle。

在swift(iOS 8和OS X 10.10)上,你可以这样做:

 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") } 

您可以使用以下代码使用UIAlerController XCode 6和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]; 

希望对你有用..