多个UIActivityViewController占位符项? [英] Multiple UIActivityViewController placeholder items?

查看:72
本文介绍了多个UIActivityViewController占位符项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIActivityItemSources似乎只能返回一种占位符项?这似乎很奇怪,因为我有一个UIActivityItemSource,它可以根据给定的活动返回字符串,NSData对象或图像.

UIActivityItemSources, it seems, can only return one kind of placeholder item? This seems strange, because I have a UIActivityItemSource that could return a string, an NSData object, or an image depending upon the activity it's given.

真的没有办法返回不止一种占位符吗?(NSArrays似乎不起作用.)

Is there really no way to return more than one kind of placeholder? (NSArrays don't seem to work.)

(我可以想象一个解决方案,其中我实例化了一堆UIActivityItemProvider实例,每个实例都支持上述不同的数据类型.但这似乎比需要做的工作还要多得多……?)

(I could imagine a solution where I instantiate a bunch of UIActivityItemProvider instances, each supporting the different datatypes mentioned above. But that seems like a lot more work than should be necessary...?)

推荐答案

如果在 itemForActivityType 函数中添加跟踪,则会看到该函数将被多次调用.每个可供共享的活动都需要一个.

If you add a trace inside your itemForActivityType function you will see that this function will be called multiple times. One for each activity available for share.

例如-如果我想为Twitter和邮件/短信共享提供不同的文本,我将具有以下内容:

For example - if I want to provide different text for Twitter and mail/sms sharing I would have something like this:

- (id) activityViewController: (UIActivityViewController*) activityViewController itemForActivityType: (NSString*) activityType {

    if (activityType == UIActivityTypePostToTwitter) {
        return @"Sharing by Twitter";
    }
    else
        return @"Other kind of sharing";

}

更新:

如果要提供不同类型的数据以共享(例如文本和图像),则需要以某种方式编写占位符函数,以便在多次调用时它返回两种不同类型的对象.

If you want to provide different types of data to share (say text and images) - you need to wrote your placeholder function in a way so it returns two different kind of object when called multiple times.

- (id) activityViewControllerPlaceholderItem: (UIActivityViewController*) activityViewController {
    static int step = 0;

    if (step == 0) {
        step = 1;
        return @"text";
    }
    else if (step == 1) {
        step = 2;
        return [UIImage imageNamed: @"image"];
    }
}

这篇关于多个UIActivityViewController占位符项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆