2011-10-29 11 views
0

initWithTitleとは異なるUIAlertViewのコンストラクタでパラメータを渡す方法があるかどうかを知りたいと思います。特に私はNSArrayを渡したいと思います。出来ますか? これはコードです:AlertViewのinitメソッドのパラメータ

@implementation UIAlertTableView 


- (id)initWithFrame:(CGRect)frame { 
if (self = [super initWithFrame:frame]) { 


    array=[NSArray arrayWithObjects:@"Capitaliz. semplice",@"Capitaliz. composta",@"Pagamenti rateali",@"Bond", nil]; 

    table = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; 

    table.delegate=self; 
    table.dataSource=self; 


    [self addSubview:table]; 
} 
return self; 
} 

おかげ

+0

私はそのコードでUIAlertViewを呼び出していません - 配列の作成のみ... – bryanmac

+0

アラートビューではマッサージ文字列を渡したいと思います。それは簡単です。 – rptwsthi

+0

この配列でアラートビューに何を期待しますか? – jrturton

答えて

1

あなた自身にそのような質問をするたびに、 "[UIClassName]クラス参照"

UIAlertViewクラス参照を検索:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html

initは文字列の配列ではなくNSStringをとります:

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate  cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... 
+0

メソッドinitWithTitleをオーバーライドできますか? –

+0

独自のメソッドを継承したり継承したり、カテゴリを拡張して拡張することができます。オーバーライドすることはできません。オーバーライドされた実装と同じシグネチャを意味するからです – bryanmac

0

私はそれを解決し、おかげでとにかく:

#import "UIAlertTableView.h" 



@implementation UIAlertTableView 

@synthesize tableSelected,fontSize; 

- (id)initWithFrame:(CGRect)frame { 
if (self = [super initWithFrame:frame]) { 
    c=0;  

    table = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; 

    table.delegate=self; 
    table.dataSource=self; 


    [self addSubview:table]; 
} 
return self; 
} 

- (void)setFrame:(CGRect)rect { 
if (c==0) 
    c++; 
else if(c==1){ 
    if([tableSelected isEqualToString:@"categorie"]) 

     array=[NSArray arrayWithObjects:@"Capitalizzazione semplice",@"Capitalizzazione composta",@"Pagamenti rateali",@"Bond", nil]; 

    else if([tableSelected isEqualToString:@"tassi"]) 

     array=[NSArray arrayWithObjects: 
       @"Tasso effettivo annuo", 
       @"Tasso effettivo mensile", 
       @"Tasso effettivo bimestrale", 
       @"Tasso effettivo trimestrale", 
       @"Tasso effettivo quadrimestrale", 
       @"Tasso effettivo semestrale", 
       @"Tasso nominale convertibile mensilmente", 
       @"Tasso nominale convertibile bimestralmente", 
       @"Tasso nominale convertibile trimestralmente", 
       @"Tasso nominale convertibile quadrimestralmente", 
       @"Tasso nominale convertibile semestralmente", 
       nil]; 

    else if([tableSelected isEqualToString:@"rate"]) 


     array=[NSArray arrayWithObjects: 
       @"Rata annuale", 
       @"Rata mensile", 
       @"Rata bimestrale", 
       @"Rata trimestrale", 
       @"Rata quadrimestrale", 
       @"Rata semestrale", 
       nil]; 
    [table reloadData]; 
    [table selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0]; 
    c++; 
} 
[super setFrame:CGRectMake(0, 0, rect.size.width, 300)]; 
self.center = CGPointMake(320/2, 480/2); 

} 
0

ポスターは別の方法を自分の問題を解決しました。しかし、はい、単純なカテゴリがうまく動作します。このように実装することができます。

-(id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitlesArray:(NSArray *)otherButtonTitles{ 
    if ((self = [self initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil])){ 
     for (NSString *buttonTitle in otherButtonTitles) { 
      [self addButtonWithTitle:buttonTitle]; 
     } 
    } 
    return self; 
} 

このメソッドは最終的なパラメータをとります。 NSStringsの配列で、文字列のタイトルのボタンを繰り返し追加します。

関連する問題