0

AlertViewにテキストフィールドを表示する簡単な方法があります。これでメモリリークを示すインストゥルメント。説明してください。iOS ARC UIAlertViewリークメモリ

- (void)method { 
NSString *value = [[NSUserDefaults standardUserDefaults] valueForKey:@"key"]; 
if (value == nil) { 

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

    alertView.tag = 101; 
    alertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
    UITextField *txtGroup = [alertView textFieldAtIndex:0]; 
    [txtGroup becomeFirstResponder]; 

    [alertView show]; 
    alertView = nil; 
} 
} 

楽器のスクリーンショットをご覧ください: enter image description here

+0

は、なぜあなたはalertView = nilを作っていますか?表示した後? –

+0

私はどこかを読んで、オブジェクトをリリースするには、使用後にnilに設定する必要があります。 – PK86

+0

ここからhttp://blog.harbinger-systems.com/2014/04/ios-memory-management-and-arc/ – PK86

答えて

0

あなたにalertViewを作成する必要があります。

static UIAlertView *alertView = nil; 

if (!alertView){ 
    alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
} 
+0

なぜUIAlertViewは静的であるべきですか? – PK86

+0

このメソッドを呼び出すと、alertviewは新しいインスタンスを作成します。 – KKRocks

+0

静的ではなくグローバルなalertiviewを宣言できます。 – KKRocks

関連する問題