0

我使用下面的代码来显示带有 Tweet、Facebook 和 Cancel 按钮的操作表。

- (void)shareApp:(id)sender {
    NSString *strCancel = NSLocalizedString(@"Cancel", nil);
    NSString *strTweet = NSLocalizedString(@"Tweet", nil);
    NSString *strFacebook = NSLocalizedString(@"Facebook", nil);

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Share your app", nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    // Create the actions.
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:strCancel style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction *action) {
                                            NSLog(@"Cancel action occured");
                                }];

    UIAlertAction *tweetAction = [UIAlertAction actionWithTitle:strTweet style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction *action) {
                                                            NSLog(@"Tweet action here");
                                                        }];

    UIAlertAction *facebookAction = [UIAlertAction actionWithTitle:strFacebook style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction *action) {
                                                            NSLog(@"Facebook action here");
                                                        }];

    // Add the actions.
    [alertController addAction:cancelAction];
    [alertController addAction:tweetAction];
    [alertController addAction:facebookAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

截屏

现在,我想在操作表的每个元素上添加自定义视图,即徽标 + 推文。

所需的屏幕截图

如何实施?

4

1 回答 1

3

我通过你的代码得到了解决方案。只需参考下面的编码

 NSString *strCancel = NSLocalizedString(@"Cancel", nil);
 NSString *strTweet = NSLocalizedString(@"Tweet", nil);
 NSString *strFacebook = NSLocalizedString(@"Facebook", nil);

 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Share your app", nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];

 UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:strCancel style:UIAlertActionStyleCancel
 handler:^(UIAlertAction *action) {
 NSLog(@"Cancel action occured");
 }];

UIAlertAction *tweetAction = [UIAlertAction actionWithTitle:strTweet style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction *action) {
                                                        NSLog(@"Tweet action here");
                                                    }];

UIAlertAction *facebookAction = [UIAlertAction actionWithTitle:strFacebook style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *action) {

                                                           NSLog(@"Facebook action here");


                                                       }];

UIImage *accessoryImage = [UIImage imageNamed:@"Twitter.jpg"];
[tweetAction setValue:accessoryImage forKey:@"image"];
UIImage *accessoryFBImage = [UIImage imageNamed:@"Facebook.png"];
[facebookAction setValue:accessoryFBImage forKey:@"image"];


[alertController addAction:tweetAction];
[alertController addAction:facebookAction];
[alertController addAction:cancelAction];

[self presentViewController:alertController animated:YES
                                      completion:nil];
于 2015-06-03T12:52:30.383 回答