呈现UIActivityViewController时发出警告

时间:2015-06-19 09:41:27

标签: ios swift xcode6 uistoryboard

当我使用下面的代码呈现public class Label { public String id; public double amount; public Label(String id, double amount) { super(); this.id = id; this.amount = amount; } public static Map<String, Label> makeUnique(List<Label> list) { Map<String, Label> map = new HashMap<String, Label>(); for (Label label : list) { if(!map.containsKey(label.id)) map.put(label.id, label); } return map; } public static void main(String[] args) { List<Label> list = new ArrayList<Label>(); list.add(new Label("1742", 10)); list.add(new Label("1742", 11)); list.add(new Label("1647", 12)); list.add(new Label("1647", 14)); Map<String, Label> map = makeUnique(list); } } 时,我会看到它,但控制台会显示“UIActivityController”。

Warning: Attempt to present <UIActivityViewController: 0x7f8788e7aed0> on <MyApp.CustomTableViewController: 0x7f8788e3db60> which is already presenting (null)

此函数由@IBAction func shareImage(sender: AnyObject) { let images: [UIImage] = [image.image!] let activityViewController = UIActivityViewController(activityItems: images, applicationActivities: nil) self.presentViewController(activityViewController, animated: true, completion: nil) } 调用。请注意,我使用的故事板具有以下层次结构:

UILongPressGestureRecognizer&gt; (关系)&gt; TabBarController&gt; (关系)&gt; NavigationController&gt; (显示)&gt; TableViewController&gt; (显示)&gt; TableViewController

演示文稿发生在最后一个ViewController上。

我很确定这是关于层次结构,控制器当前正在呈现(以及可能如何)以及哪个控制器负责呈现ViewController

修改

多次调用

UIActivityViewController触摸事件导致警告

2 个答案:

答案 0 :(得分:7)

很难从您的问题中说出来,但目前还有其他一些视图控制器出现了吗?例如和行动表或其他?

无论如何,试试这个:

    if self.presentedViewController != nil {
        self.dismissViewControllerAnimated(false, completion: {
            [unowned self] in
            self.presentViewController(activityViewController, animated: true, completion: nil)
            })
    }else{
        self.presentViewController(activityViewController, animated: true, completion: nil)
    }

答案 1 :(得分:0)

我收到相同的错误消息,因为UILongPressGestureRecognizer多次调用选择器。现在,当UILongPressGestureRecognizer状态结束时,我将调用UIActivityViewController。

#I have input a string value beforehand.

name='George'
if name==True:
    print('name is given')
else:
    print('Name Not Given')

#this gives the following output:
>>>Name Not Given