2012-03-14 4 views
0

カスタマイズに関するご質問がありますUIAlertViewUIAlertViewにカスタムUIbuttonを追加するには?

UIAlertViewは、背景とボタンでもカスタマイズできます。カスタムボタンを追加しますが、ボタンのアクションをトリガーすることはできません。カスタムボタンはUIAlertViewに追加されますが、どのようにアクションを追加できないのですか?私を助けてください。それはUIAlertViewが私たちにカスタムボタンを持たせることができないからですか?

UIButton *firstButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 120, 90, 30)]; 
UIButton *secondButton = [[UIButton alloc] initWithFrame:CGRectMake(180, 120, 90, 30)]; 

UIImage *btnImage = [UIImage imageNamed:kButtonBlackImage]; 

[firstButton setBackgroundImage:btnImage forState:UIControlStateNormal]; 
[firstButton setTitle:@"Don't Favorite" forState:UIControlStateNormal]; 
firstButton.titleLabel.font = BOLDFONTSMALL; 
[firstButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[firstButton addTarget:self action:@selector(cancelFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

[secondButton setBackgroundImage:btnImage forState:UIControlStateNormal]; 
[secondButton setTitle:@"Save Favorite" forState:UIControlStateNormal]; 
[secondButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
secondButton.titleLabel.font = BOLDFONTSMALL; 
[secondButton addTarget:nil action:@selector(addFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

[alert addSubview:firstButton]; 
[alert addSubview:secondButton]; 
+0

あなたの必要性は正確に –

+0

うまくいくはずです。ここであなたのalertviewのスクリーンショットを追加できますか?そしてalertviewをどのように割り当てましたか? – Dee

+0

私が推測する必要はありません、それはAppleのルールに違反し、あなたのアプリケーションは拒否される可能性が高いです – doNotCheckMyBlog

答えて

0
[firstButton addTarget:self action:@selector(cancelFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

Add that buttons properly 
0

あなたはUIAlertViewにカスタムビューを使用することができます。私はできるよ

UIAlertView*testAlert=[[UIAlertView alloc] initWithFrame:CGRectMake(0, 0, 140, 140)]; 
[testAlert show]; 
UIButton*testButton=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[testButton setFrame:CGRectMake(0, 0, 40, 40)]; 
[testButton addTarget:self action:@selector(someAction) forControlEvents:UIControlEventTouchUpInside]; 
[testAlert addSubview:testButton]; 

:あなたはnilとして目標を設定し、多分ので、あなたのsecondButtonその問題に問題がある場合、それはself

[secondButton addTarget:self action:@selector(addFavorite:) forControlEvents:UIControlEventTouchUpInside]; 

ちょうど試み、それが作業してしまったする必要があります私のsomeActionメソッドを使用する。

関連する問題