UIAlertController循环引用问题

本文介绍了一个使用 Swift 语言实现的 UIAlertController 示例。示例中定义了一个弱引用的 alert 方法,并通过 UIAlertAction 添加了一个具有破坏性的操作,点击该操作时会记录下两个文本字段的内容。
__weak typeof (alert) weekAlert=alert;
   [alert addAction:[UIAlertAction actionWithTitle:@"submit" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
         NSLog(@"click submit button");

         NSLog(@"first textField‘s text is %@,the second textField‘s text is %@",[weekAlert.textFields.firstObject text],[weekAlert.textFields.lastObject text]);
     }]];
{ NSString *lockString = @"剧集解锁状态"; for (int i= 0; i < infoModel.lockStatusArray.count; i++) { NSNumber *status = infoModel.lockStatusArray[i]; lockString = [lockString stringByAppendingFormat:@"%@%@集-%@", i == 0 ? @":":@",", @(i+1), status.intValue == 1 ? @"已解锁":@"未解锁"]; } NSLog(@"[短剧解锁开始回调]%@", lockString); if ([extraInfo valueForKey:@"isContinuityUnlock"]) { //连续解锁逻辑 NSInteger current_unlock_episode = [[extraInfo valueForKey:@"current_unlock_episode"] integerValue]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"看广告解锁" message:[NSString stringWithFormat:@"看一个激励广告解锁%ld集,\n 再看一次广告解锁%@集-%@集", self.unlockCountPerAD, @(current_unlock_episode), @(current_unlock_episode + self.unlockCountPerAD)] preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.cancelUnlock = YES; unlockInfo.unlockModeType = DJXPlayletUnlockModeType_Continuous; unlockInfoHandler(unlockInfo); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"看广告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.playletId = infoModel.shortplay_id; unlockInfo.unlockEpisodeCount = self.unlockCountPerAD; unlockInfo.unlockModeType = DJXPlayletUnlockModeType_Continuous; unlockInfoHandler(unlockInfo); }]]; [self.presentedViewController presentViewController:alert animated:YES completion:nil]; } else { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"看广告解锁" message:[NSString stringWithFormat:@"看一个激励广告解锁%ld集", self.unlockCountPerAD] preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.cancelUnlock = YES; unlockInfo.unlockModeType = self.unlockModeType; unlockInfoHandler(unlockInfo); }]]; [alert addAction:[UIAlertAction actionWithTitle:@"看广告" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { DJXPlayletUnlockModel *unlockInfo = [[DJXPlayletUnlockModel alloc] init]; unlockInfo.playletId = infoModel.shortplay_id; unlockInfo.unlockEpisodeCount = self.unlockCountPerAD; unlockInfo.unlockModeType = self.unlockModeType; unlockInfoHandler(unlockInfo); }]]; [self.presentedViewController presentViewController:alert animated:YES completion:nil]; } } 帮我转成swift的写法
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值