how to use UIActivityViewController with MonoTouch

久未见 提交于 2019-12-21 19:58:15

问题


I am trying to access UIActivityViewController from MonoTouch with the following code:

var textToShare = new NSString("hallo there");
var activityItems = new NSObject[] {textToShare};
var excludedActivityTypes = new NSString[] { new NSString("UIActivityTypePostToWeibo"),       new NSString("UIActivityTypeMessage") };
var activityViewController = new UIActivityViewController(activityItems, null);
activityViewController.ExcludedActivityTypes = excludedActivityTypes;
this.PresentViewController(activityViewController, true, null)

The iOS action sheet is displayed but the specified activities are not excluded. Any suggestions what the problem is? Are there any MonoTouch samples for this?


回答1:


You were close. Change this:

var excludedActivityTypes = new NSString[] { 
    new NSString("UIActivityTypePostToWeibo"),
    new NSString("UIActivityTypeMessage") 
};

into:

var excludedActivityTypes = new NSString[] {
    UIActivityType.PostToWeibo,
    UIActivityType.Message
};

Note: The name of the constant is not always identical to it's value. Also it's common (even if bad practice) for ObjC to compare the NSString pointers (not their values) to detect constant equality - creating your own NSString instance won't work in such cases (anyway the exposed const are much better looking and work better with code completion from the IDE).



来源:https://stackoverflow.com/questions/13351380/how-to-use-uiactivityviewcontroller-with-monotouch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!