@objc func printNum() {
print(”hello world”)
}
this function can be used with objective c code.
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareFlag))
@objc func shareFlag() {
guard let image = ImageView.image?.jpegData(compressionQuality: 0.8) else {
print("No image found")
return
}
// this shares two things an image and a name the commented line below only shares an image
let vc = UIActivityViewController(activityItems: [title ?? "Unknown country", image], applicationActivities: [])
// let vc = UIActivityViewController(activityItems: [image], applicationActivities: [])
vc.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(vc, animated: true)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return pictures_hd.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Picture", for: indexPath)
cell.textLabel?.text = "\(indexPath.row+1). " + pictures_hd[indexPath.row].replacingOccurrences(of: ".png", with: "")
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let vc = storyboard?.instantiateViewController(withIdentifier:"Detail") as? DetailViewController {
let sortedPictures = pictures_hd.sorted()
vc.selectedImage = sortedPictures[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
}
}
// to remove a cell
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
print("Deleted")
self.items.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .automatic)
}
}