多个UIAlertView的使用

在同一个ViewController里面,当我们需要同时用到多个UIAlertView来提示不同的信息时。可以直接定义。

UIAlertView *view = [[[UIAlertView allocinitWithTitle@"Choose Configuration:" message@""delegateself cancelButtonTitle@"Production" otherButtonTitles@"Staging",

#if DEBUG

@"Development",

#endif

@"Reset Prefs and Quit"nilautorelease];

[view setTag1];


#if BYPASS_CONFIG_ALERT

#warning Config alert bypassed!

[self alertView: view clickedButtonAtIndex2];

#else

[view show];

#endif

但是,当我们只需要提示信息,不需要响应一些事件时,可以将delegate:nil,设置成nil;

当我们需要对多个UIAlertView的多个button按钮响应事件时,我们此时就需要分清楚,当前显示的UIAlertView到底是哪一个的UIAlertView。此时,我们有一种方法,当我们定义UIAlertView时,我们可以设置它的tag。这样我们就可以使用tag来区分到底当前显示的是哪一个UIAlertView。

- (void) alertView:(UIAlertView *) inAlertView clickedButtonAtIndex:(NSInteger) buttonIndex

{

switch ( [inAlertView tag] )

{

case 0:

{

// network timeout alert

self.alert = nil;

switch ( buttonIndex ) 

{

case 0

{

// cancel

exit0 );

break;

case 1

{

// retry

self.loadTime = [NSDate date];

self.timer = [NSTimer scheduledTimerWithTimeInterval:kXMLLookupTimeout targetself selector@selector(timeout:) userInfonil repeatsNO];

break;

}

break;

case 1

{

// debug preferences alert

NSUserDefaults *defaults;

NSString *key, *lastStartupMethod, *startupMethod;

NSEnumerator *keyEnumerator;

BOOL resetPreferences = NO;

defaults = [NSUserDefaults standardUserDefaults];

lastStartupMethod = [defaults objectForKey@"lastStartupMethod"];

switch ( buttonIndex )

{

case 0

{

// production config files

startupMethod = @"Release";

break;

case 1:

{

// staging config files

startupMethod = @"Debug";

[ConfigFileFetcher setUseDebugFilesYES directory:@"staging"];

break;

#if DEBUG

case 2

{

// development config files

startupMethod = @"Debug";

[ConfigFileFetcher setUseDebugFilesYES directory:@"development"];

break;

#endif

default

{

// reset prefs & quit

startupMethod = nil;

resetPreferences = YES;

break;

}

resetPreferences |= lastStartupMethod && ! [lastStartupMethodisEqualToString: startupMethod];

if ( resetPreferences )

{

keyEnumerator = [[defaults dictionaryRepresentation]keyEnumerator];

while ( ( key = [keyEnumerator nextObject] ) )

{

[defaults removeObjectForKey: key];

}

}

if ( startupMethod ) [defaults setObject: startupMethod forKey:@"lastStartupMethod"];

[defaults synchronize];

if ( buttonIndex == 3 )

{

exit0 );

else

{

[self applicationDidFinishLaunchingActual: [UIApplicationsharedApplication]];

}

break;

case kTagAlertTerminateApp

{

// application too old alert

exit0 );

break;

case kTagAlertVideo:

{

NSString *videoURL;

switch ( buttonIndex )

{

case 1:

videoURL =pendingVideoStation.videoURLLowBandwidth;break;// yes play low bandwidth video

case 2:

videoURL = pendingVideoStation.videoURL;break;// no play high bandwidth video

default:

videoURL = nil;break;// cancel

}

if ( videoURL )

{

[PlayerViewController shared].station = nil;

[VideoController showVideo: videoURL];

}

self.pendingVideoStation = nil;

break;

}

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值