Skip to content

Instantly share code, notes, and snippets.

View hasanalisiseci's full-sized avatar
🏠
Working from home!

Hasan Ali hasanalisiseci

🏠
Working from home!
View GitHub Profile
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let numOfFruits = fruits.count
return numOfFruits
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = fruits[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alert = UIAlertController(title: "Fruits", message: "This fruit is \(fruits[indexPath.row])", preferredStyle: UIAlertController.Style.alert)
let okButton = UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil)
alert.addAction(okButton)
self.present(alert, animated: true, completion: nil)
}
@IBAction func nextButtonClicked(_ sender: Any) {
performSegue(withIdentifier: "toSecondVC", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toSecondVC" {
//as ile casting
let destination = segue.destination as! SecondViewController
destination.myName = name
}
}
override func viewDidLoad() {
super.viewDidLoad()
imageView.isUserInteractionEnabled = true // Görseli tıklanabilir hale getirdik.
//Gesture Recognizer'ı oluşturup action kısmında içine "changePic" fonskiyonunu gönderdik
let changeGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(changePic))
//Daha sonra Gesture Recognizer'ı görselimze ekledik.
imageView.addGestureRecognizer(changeGestureRecognizer)
@objc func changePic() {
if isOldCeza == true {
imageView.image = UIImage(named: "cezaeski")
myLabel.text = "Ceza 2007"
isOldCeza = false
} else {
imageView.image = UIImage(named: "cezayeni")
myLabel.text = "Ceza 2020"
isOldCeza = true
override func viewDidLoad() {
super.viewDidLoad()
let keyboardGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(hideKeyboard)) // Gesture Recognizer'ı oluşturup içine hideKeyboard fonksiyonumuzu gönderdik.
view.addGestureRecognizer(keyboardGestureRecognizer) // Gesture Recognizer'ı tüm görünüme ekledik.
}
@objc func hideKeyboard() {
view.endEditing(true) //Klavyeyi kapatmamızı sağlayan fonksiyon.
}
func getLyric() {
// Hedef URL'yi tanımlıyoruz
let url = URL(string: "https://api.kanye.rest/?format=text")
do {
//URL ile ulaştığımız veriyi String olarak alıyoruz.
let contents = try String(contentsOf: url!)
//String değeri text view'a gönderiyoruz.
textView.text = "\"\(contents)\""
} catch {
// İçerik yüklenemez ise