我有一個資料陣列 "電",我正在從服務器上獲取。我在UITableView的單元格里有一個按鈕,名字叫 "copyPinButton"。在 "cellForRowAt indexPath "中,我必須放置資料。我想復制一個字串,這個字串是我通過按'copyPinButton'從服務器上得到的。謝謝。
import UIKit
class ElectricityBillTransactionHistoryViewController。BaseViewController {
@IBOutlet weak var electricityTransactionHistoryTableView: UITableView!
private var electricity = [Electricity]()
override func viewDidLoad() {
super.viewDidLoad()
electricityTransactionHistoryTableView.delegate=self
electricityTransactionHistoryTableView.dataSource = self
electricityTransactionHistory()
}
func electricityTransactionHistory() {
webserviceHandler.transactionHIstory(onCompletion: { (TransactionHistoryResponse) in
if TransactionHistoryResponse.code == 200 {
self.電 = TransactionHistoryResponse.data?.電 ?
self.electricTransactionHistoryTableView.delegate = self.
self.electricTransactionHistoryTableView.dataSource= self
self.electricTransactionHistoryTableView.reloadData()
}else {
self.showDialog(標題。nil, message: TransactionHistoryResponse.message ? K.Messages.DefaultErrorMessage,onDefaultActionButtonTap: nil)
}
}, onFailure: { ( _) in)
self.showDialog(title: nil, message: K.Messages.DefaultErrorMessage, onDefaultActionButtonTap: nil)
}, shouldShowLoader: true)
}
}
extension ElectricityBillTransactionHistoryViewController。UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return electricity.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "electricTransactionHistoryTableViewCellId"/span>, for: indexPath) 作為! electricityTransactionHistoryTableViewCell
let electricityData = electricity[indexPath.row] 。
cell.electricBillHistoryTitleLabel.text = electricityData.packName
cell.electricBillTransactionIdLabel.text = "( electricityData.trackerID ? 0)"
cell.electricBillAmountLabel.text = "(electricData.paidAmount ? ? 0)"
cell.electricBillPaymentDateLabel.text = Util.getFormattedDateString(inputDateString: electricityData.purchatedDate ? ", inputDateFormat: "yyyy-MM-dd'T'HH:mm:ss.SSSZ", outputDateFormat: "dd MMM yyyy - h:mm a")
return cell
}
}
class electricityTransactionHistoryTableViewCell。UITableViewCell {
@IBOutlet weak var electricityBillContainerView: UIView!
@IBOutlet weak var copyPinButton: UIButton!
@IBOutlet weak var electricityBillImageView: UIImageView!
@IBOutlet weak var electricityBillHistoryTitleLabel: UILabel!
@IBOutlet weak var electricityBillAmountLabel: UILabel!
@IBOutlet weak var electricityBillMonthLabel: UILabel!
@IBOutlet weak var electricityBillTransactionIdLabel: UILabel!
@IBOutlet weak var electricityBillPaymentDateLabel: UILabel!
override func awakeFromNib() {
copyPinButton.layer.masksToBounds = false
copyPinButton.layer.shadowColor = UIColor.grey.cgColor
copyPinButton.layer.shadowOpacity = 0.5。
copyPinButton.layer.shadowOffset = CGSize(width: 1.5, height: 0.5)
copyPinButton.layer.shadowRadius = 3
electricityBillContainerView.layer.masksToBounds = false
electricityBillContainerView.layer.shadowColor = UIColor.grey.cgColor
electricityBillContainerView.layer.shadowOpacity = 0.5
electricityBillContainerView.layer.shadowOffset = CGSize(width: 2.0, height: 0.5)
electricityBillContainerView.layer.shadowRadius = 3
}
@IBAction func copyButtonTapped(_ sender: Any) {
}
uj5u.com熱心網友回復:
直接使用UIPasteboard
// write to clipboard
UIPasteboard.general.string = "Hello world"/span>
//從剪貼板讀取
let content = UIPasteboard.general.string
檢查這個問題以獲得更詳細的答案
。uj5u.com熱心網友回復:
你可以使用UIPasteboard復制文本或字串,如下:
@IBAction func copyButtonTapped(_ sender: Any) {
UIPasteboard.general.string = "你的價值"。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/311748.html
標籤:
