2016-06-17 14 views
-4

私は最初のiOSアプリケーションを作成しようとしており、このチュートリアルではUIAlertViewの使用を依頼しました。 XCodeはこれが非難され、UIAlertControllerを使うべきだと私に伝えました。私はUIAlertViewのインスタンスをUIAlertControllerに置き換え、まだ問題に遭遇しています。「UIAlertControllerの表示されない@interfaceはセレクタのinitWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: ' を宣言します。 。私のコードは以下の通りです:。。IOS/Objective C開発の新機能、 UIAlertView/Controllerの問題

// 
// ViewController.m 
// cv 
// 
// Created by Frank Michael Tocci on 6/17/16. 
// Copyright © 2016 Frank Tocci. All rights reserved. 
// 

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    UIAlertController * alert = [[UIAlertController alloc] initWithTitle:@"Hello!" message:@"Welcome to OpenCV" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil]; 
    [alert show]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

'UIAlertView'と' UIAlertController'は2つの異なるものです。また、 'UIAlertView'は非推奨です。 – liamnichols

+1

UIalertControllerのドキュメントとその使い方をお読みください! –

答えて

0

UIAlertControllerは、あなたがそれを初期化し、それは違う表示UIAlertView

方法ではありません。ここで方法は次のとおりです。あなたがiOSの8のためにアプリケーションをデプロイしている場合

// Init the alert 
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" 
               message:@"This is an alert." 
               preferredStyle:UIAlertControllerStyleAlert]; 

// Setup the action for the alert 
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" 
               style:UIAlertActionStyleDefault 
               handler:^(UIAlertAction * action) {}]; 

// Add the defaultAction to the alert (this will add an action button with title "OK" to the alert) 
[alert addAction:defaultAction]; 

// Display it 
[self presentViewController:alert animated:YES completion:nil]; 
+0

これがなぜ投票されたのか分かりませんが、これは私のために働いた –

+0

おそらく投票結果が下がったのは、違いを説明してAppleのドキュメントにリンクするのではなく、 –

2

UIAlertControllerはUIAlertViewとは異なるインターフェースを持っているあなただけのタイトル、メッセージ、および好みのスタイルを取り入れ異なるコンストラクタを使用する必要があります

次に、あなたがにアクションを追加することができます一度定義されたUIAlertController。ハイパーリンクをクリックすると、Appleのマニュアルが表示されます。 UIAlertControllerの使い方の例。

0

その後、ちょうどあなたがAlertViewを使用するための任意の減価償却費を見つけることができません。この後のiOS 8にデプロイメント・ターゲットを変更します。 AlertViewはiOS 9以降では下位になりますが、iOS 9ではそれでも問題なく動作します。