我有兩個樣品按鈕,並與他們每個人的,兩個不同的alertView
應單獨彈出。第一個效果不錯,但是打到第二個,不知道爲什麼兩個alertView
一個接一個彈出來。AlertView彈出兩次單按鈕
下面是代碼:
- (IBAction)AlertViewButtonTwo:(id)sender
{
UIAlertView *myAlertOne = [[UIAlertView alloc] initWithTitle:@"AlertView" message:@"AlertViewOne" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"GoToYahoo", @"GoToYoutube", @"GoToFacebook", nil];
myAlertOne.tag = 1;
[myAlertOne show];
}
- (IBAction)AlertViewButtonThree:(id)sender
{
UIAlertView *myAlertTwo = [[UIAlertView alloc] initWithTitle:@"AlertView" message:@"AlertViewTwo" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"GoToDailyStar", @"GoToProthomAlo", @"GoToNewAgeBD", nil];
myAlertTwo.tag = 2;
[myAlertTwo show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 1)
{
if (buttonIndex == 0)
{
// this is the cancel button
}
else if (buttonIndex == 1)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.yahoo.com/"]];
}
else if (buttonIndex == 2)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.youtube.com/"]];
}
else if (buttonIndex == 3)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/"]];
}
}
else if (alertView.tag == 2)
{
if (buttonIndex == 0)
{
// this is the cancel button
}
else if (buttonIndex == 1)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.thedailystar.net/"]];
}
else if (buttonIndex == 2)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.prothom-alo.com/"]];
}
else if (buttonIndex == 3)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.newagebd.com/"]];
}
}
}
我是新來的iOS中。如果有人告訴我這個缺點,那將是非常可觀的。 在此先感謝。
你是如何創建按鈕並設置目標的? – Wain
對不起,我沒聽懂你...北斗星 – Tulon