2012-04-25 9 views
0

のような警告メッセージを表示する必要がありますか?本当ですか? [Y/N] WARNING - これについてはこれがスコアをリセットします「UIAlertViewメッセージディスプレイ

私は次のコード行を書いています:。これにより

UIAlertView *alert = [[UIAlertView alloc] init]; 
    [alert setMessage: NSLocalizedString(@"Are you sure?", nil)]; 
    [alert setTitle:@"WARNING - This will reset scores."]; 
    [alert addButtonWithTitle:@"Y"]; 
    [alert addButtonWithTitle:@"N"]; 
    [alert setDelegate:self]; 
    [alert show]; 
    [alert release]; 

私は、最初の質問で警告テキストを取得していますし、ボタン。私はその警告テキストを最後に表示したい。 フローは最初の質問(あなたは本当ですか?)、次に2つのボタン(Y/N)、警告テキストのようになります。私はこれで構造化しています。助けてください。

+0

下記の答えに従ってください。 –

答えて

0

現在、メッセージの上に表示されるように、警告テキストがタイトルとして表示されています。あなたのsetMessageは、以下のようなものに変更します。

NSString *fullMessage = [NSString stringWithFormat:@"%@\n\nWARNING - This will reset scores.", NSLocalizedString(@"Are you sure?", nil)]; 
[alert setMessage: fullMessage]; 
+0

これは警告テキストの行番号を変更するだけですが、表示したいのは、です。最初に "Are you Sure?"を入力し、次に2つのボタン(Y/N)を押して、警告テキストを表示します。 – hgpl

+0

ありがとうございます。私を助けてください。 – hgpl

+1

ああ、あなたは組み込みのUIAlertViewでそのようなレイアウトをすることはできません。そのようなもの(AFAIK)のための独自のカスタムビューを作成する必要があります。 – keno

1
UIAlertView *alert1= [[UIAlertView alloc]initWithTitle:@"Are you sure?" message:@"Warning-This will reset scores." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Y",@"N", nil]; 
[alert1 show]; 
[alert1 release];  

使おシンプルなinitメソッド!!

1

カスタムAlertViewを作成する必要があります。ここに私のカスタムAlertViewコードがあります。あなた自身の必要なalertViewを作成するためにそれをたどることができます。おそらくそれはあなたを助けるでしょう。

#import <UIKit/UIKit.h> 
#import "Utility.h" 

@interface AlertViewController : UIViewController <UIAlertViewDelegate> 
{ 
    UITextView   *_sharingTextView; 
} 
- (void) showAlertViewWithTextView; 
@end 

そして.Mファイルに

#import "AlertViewController.h" 

@implementation AlertViewController 

#define AlertViewIphoneInitFrame CGRectMake(0, 0, 300, 100) 
#define AlertViewIpadInitFrame CGRectMake(200, 50, 600, 200) 
#define TextViewIphoneFrame CGRectMake(20, 50, 260, 80) 
//#define TextViewIpadFrame CGRectMake(40, 100, 520, 160) 
#define AlertViewIphonePresentFrame CGRectMake(10, 100, 300, 200) 
#define AlertViewIpadPresentFrame CGRectMake(200, 200, 600, 400) 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - Custom AlertView 
//Custom AlertView 
- (void) showAlertViewWithTextView 
{ 
    UIAlertView *alert; 
    if ([[Utility getCurrentDevice] isEqualToString:@"iPad"]) 
    { 
     alert = [[UIAlertView alloc] initWithFrame:AlertViewIpadInitFrame]; 
     _sharingTextView = [[UITextView alloc] initWithFrame:TextViewIphoneFrame]; 
    } 
    else 
    { 
     alert = [[UIAlertView alloc] initWithFrame:AlertViewIphoneInitFrame]; 
     _sharingTextView = [[UITextView alloc] initWithFrame:TextViewIphoneFrame]; 
    } 
    alert.title = @"History Application"; 
    alert.message = nil; 
    alert.delegate = self; 
    [alert addButtonWithTitle:@"Return"]; 

    _sharingTextView.text = @"To share you events through tweets or facebook sharing you have to login, You can do so here or when trying to tweet or facebook share. You can also logout here"; 
    [_sharingTextView setFont:[UIFont fontWithName:@"Helvetica" size:18.0]]; 
    [_sharingTextView setEditable:NO]; 
    [alert addSubview:_sharingTextView]; 
    [alert show]; 
    [_sharingTextView release]; 
    [alert release]; 
} 

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
} 

// to set the alertView frame size. 
- (void)willPresentAlertView:(UIAlertView *)alertView 
{ 
    if ([[Utility getCurrentDevice] isEqualToString:@"iPad"]) 
    { 
     [alertView setFrame:AlertViewIpadPresentFrame]; 
    } 
    else 
    { 
     [alertView setFrame:AlertViewIphonePresentFrame]; 
    } 
    [alertView setFrame:AlertViewIphonePresentFrame]; 
    for (UIView *views in [alertView subviews]) 
    { 
     NSLog(@"%@",views); 
     if (views.tag == 1) 
     { 
      [views setFrame:CGRectMake(views.frame.origin.x+10, views.frame.origin.y+80, views.frame.size.width, views.frame.size.height)]; 
     } 
    } 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (void)dealloc { 
} 

@end