gpt4 book ai didi

swift - 我需要更改此代码才能使文本显示在共享表中?

转载 作者:行者123 更新时间:2023-11-30 10:15:17 26 4
gpt4 key购买 nike

我的文本没有显示在它所说的调试区域

“[6384:3178597] 插件 com.apple.share.Facebook.post 无效”

我一直在使用的代码如下:

@IBAction func Share(sender: AnyObject) { 
let firstActivityItem = " Hello "
let ActivityViewController : UIActivityViewController = UIActivityViewController(activityItems: [firstActivityItem], applicationActivities: nil)
self.presentViewController(ActivityViewController, animated: true, completion: nil)
}

此外,如果有人能给我添加图像的代码和操作表的链接,那也会非常有帮助

最佳答案

按照这个例子:

class DataToShow{
var url: String = ""
var text: String = ""
var image: UIImage?
}

var myData: DataToShow!

@IBAction func shareButtonClick(sender: UIButton) {
let firstActivityItem = myData.text
let secondActivityItem : NSURL = NSURL(string: myData.url)!
let image : UIImage? = myData.image

var activities = [firstActivityItem, secondActivityItem]
if image != nil{
activities.append(image!)
}

let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: activities, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros

//This part is to center it on current UIViewController
let x = self.view.center
activityViewController.view.frame.origin.x = x.x
activityViewController.view.frame.origin.y = x.y

activityViewController.popoverPresentationController?.sourceRect = CGRectMake(x.x, x.y, 0, 0)
activityViewController.popoverPresentationController?.delegate = self

self.presentViewController(activityViewController, animated: true, completion: nil)
}

//This is for maintening it centered when changing orientation...
override func popoverPresentationController(popoverPresentationController: UIPopoverPresentationController, willRepositionPopoverToRect rect: UnsafeMutablePointer<CGRect>, inView view: AutoreleasingUnsafeMutablePointer<UIView?>) {
let x = popoverPresentationController.presentingViewController.view.center
var newRect = CGRectMake(x.x , x.y, 0, 0)
rect.initialize(newRect)
}

这已在 iPad 和 iPhone 上进行了测试。代码的居中部分仅适用于 iPad,在 iPhone 上它的行为有所不同。

关于swift - 我需要更改此代码才能使文本显示在共享表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30465694/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com