簡體   English   中英

將UITextField連接到SLComposeViewController-swift

[英]connecting a UITextField to an SLComposeViewController - swift

我正在嘗試將SLComposeViewController的默認文本設置為用戶通過將其轉換為字符串而輸入到UITextField中的內容,但是它沒有顯示在SLComposeViewController中。

@IBOutlet weak var textField: UITextField!
var userTextInput: String = ""

@IBAction func shareFacebookButton(_ sender: AnyObject)
{
    if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook){
        let facebookPost = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
        facebookPost!.setInitialText(userTextInput)
        self.present(facebookPost!, animated: true, completion: nil)
    }
    else
    {
        print("Error")

}
}

我試着做一個字符串bur,我需要讓它使用變量userTextInput中的String變量textField。

但在繼續之前

Facebook不再允許預先填充消息 ,有關更多信息,請點擊此處

您可以直接附加文本字段值以進行共享,例如

if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook){
    let facebookPost = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
    facebookPost!.setInitialText(textField.text)
    self.present(facebookPost!, animated: true, completion: nil)
}
else
{
    print("Error")
}

更新

您可以檢查textfield是否包含文本,如果可以,則可以在facebook中共享,例如

if !textField.text.isEmpty
{
 if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook){
    let facebookPost = SLComposeViewController(forServiceType:SLServiceTypeFacebook)
    facebookPost!.setInitialText(textField.text)
    self.present(facebookPost!, animated: true, completion: nil)
}
else
{
    print("Error")
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM