首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >触发第二个UIAlertController ActionSheet的ActionSheet

触发第二个UIAlertController ActionSheet的ActionSheet
EN

Stack Overflow用户
提问于 2016-06-23 05:26:57
回答 1查看 173关注 0票数 0

对于我的应用程序,我有一个领域,我想选择做两个行动单。当触摸一个TableView上的行来为一个选项投票时,它提供了3个选择,拇指向上,拇指向下,或者查看建议的日期。单击拇指向上应该会给出另一个有可用日期的操作表。我把它弹出第二个工作表,但是它会被自动删除,这要归功于代码self dismissViewController将两者都删除,而不仅仅是其中的一个。我有什么办法能做得更好吗?

代码语言:javascript
复制
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Vote" message:@"Please vote thumbs up or thumbs down for this activity.  Vote only one time, please, except for Cricket who may vote again for Casey...who still doesn't have an iPhone.  Cricket, use this power wisely." preferredStyle:UIAlertControllerStyleActionSheet];
    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

        // Cancel button tappped.
        [self dismissViewControllerAnimated:YES completion:^{
        }];
    }]];

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Thumbs Up" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {



        UIAlertController *actionSheet2 = [UIAlertController alertControllerWithTitle:@"Date" message:@"What Date?" preferredStyle:UIAlertControllerStyleActionSheet];
        [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

            // Cancel button tappped.
            [self dismissViewControllerAnimated:YES completion:^{
            }];
        }]];

        [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Sunday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [self dismissViewControllerAnimated:YES completion:^{
                //Sunday
                [entry addObject:@"Sunday" forKey:@"DatesSuggested"];
                [entry saveInBackground];
                [self loadObjects];

            }];
        }]];

        [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Monday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [self dismissViewControllerAnimated:YES completion:^{
                //Sunday
                [entry addObject:@"Monday" forKey:@"DatesSuggested"];
                [entry saveInBackground];
                [self loadObjects];

            }];
        }]];

        [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Tuesday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [self dismissViewControllerAnimated:YES completion:^{
                //Sunday
                [entry addObject:@"Tuesday" forKey:@"DatesSuggested"];
                [entry saveInBackground];
                [self loadObjects];

            }];
        }]];


        [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Wednesday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [self dismissViewControllerAnimated:YES completion:^{
                //Sunday
                [entry addObject:@"Wednesday" forKey:@"DatesSuggested"];
                [entry saveInBackground];
                [self loadObjects];

            }];
        }]];


        [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Thursday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [self dismissViewControllerAnimated:YES completion:^{
                //Sunday
                [entry addObject:@"Thursday" forKey:@"DatesSuggested"];
                [entry saveInBackground];
                [self loadObjects];

            }];
        }]];


        [actionSheet2 addAction:[UIAlertAction actionWithTitle:@"Friday" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [self dismissViewControllerAnimated:YES completion:^{
                //Sunday
                [entry addObject:@"Friday" forKey:@"DatesSuggested"];
                [entry saveInBackground];
                [self loadObjects];

            }];
        }]];


        [self presentViewController:actionSheet2 animated:YES completion:^{

        }
         ];







        NSInteger numberFor = [entry[@"VotesFor"] intValue];
        NSInteger newValue = numberFor + 1;
        NSString *newVotesFor = [NSString stringWithFormat: @"%ld", (long)newValue];

        [entry setObject:newVotesFor forKey:@"VotesFor"];
        [entry saveInBackground];
        [self loadObjects];
        // Distructive button tapped.
        [self dismissViewControllerAnimated:YES completion:^{
        }];
    }]];

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"Thumbs Down" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSInteger numberAgainst = [entry[@"VotesAgainst"] intValue];
        NSInteger newValue1 = numberAgainst + 1;
        NSString *newVotesAgainst = [NSString stringWithFormat: @"%ld", (long)newValue1];

        [entry setObject:newVotesAgainst forKey:@"VotesAgainst"];
        [entry saveInBackground];
        [self loadObjects];
        // OK button tapped.

        [self dismissViewControllerAnimated:YES completion:^{
        }];
    }]];

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"View Proposed Dates" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        DetailsViewController *theDetails = [[DetailsViewController alloc] init];
        theDetails.theActivity = entry;
        // OK button tapped.
         [self.navigationController pushViewController:theDetails animated:YES];
        [self dismissViewControllerAnimated:YES completion:^{

        }];
    }]];

    // Present action sheet.
    [self presentViewController:actionSheet animated:YES completion:nil];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-23 05:30:59

先解散后再提交另一份。

代码语言:javascript
复制
[self dismissViewControllerAnimated:YES completion:^{
    [self presentViewController:actionSheet2 animated:YES completion:^{
    }];
}];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37982998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档