【发布时间】:2015-07-10 05:31:17
【问题描述】:
我已经实现了我的按钮:
import UIKit
class ShareButton {
var status_title: String!
var status_content: String!
var button: UIBarButtonItem!
init(status_title: String ,status_content: String) {
button = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Action, target: self, action: Selector("btn"))
self.status_title = status_title
self.status_content = status_content
}
func btn()
{
let application = UIApplication.sharedApplication()
var can_open = application.canOpenURL(NSURL(string: "whatsapp://")!)
if (can_open) {
let url_string = "whatsapp://send?text=" + status_content
let url: NSURL = NSURL(string: url_string)!
application.openURL(url)
}
else {
let alert = UIAlertView()
alert.title = "You don't have WhatsApp"
alert.message = "You need WhatsApp to share this status"
alert.addButtonWithTitle("Got it")
alert.show()
}
}
}
但是当我点击按钮时,应用程序崩溃了......
我很乐意为您提供帮助, 非常感谢您的帮助!
【问题讨论】:
-
永远不要说“应用程序崩溃”。说出崩溃发生在哪一行以及控制台消息是什么。
-
谢谢!我会改的。
标签: ios swift uibutton uibarbuttonitem