Create a gist now

Instantly share code, notes, and snippets.

Embed
Static TableView, Galeri ve Kameradan Görüntü Alma Örnegi | Swift ----http://www.bulentsiyah.com/static-tableview-galeri-ve-kameradan-goruntu-alma-ornegi-swift/
//
// BildirTableViewController.swift
// Bildir-Basic
//
// Created by Bülent Siyah on 12.05.2018.
// Copyright © 2018 Bülent Siyah. All rights reserved.
//
import UIKit
import CoreLocation
class BildirTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, CLLocationManagerDelegate, UITextViewDelegate{
@IBOutlet weak var aciklamattext: UITextView!
@IBOutlet weak var konuSecimi: UILabel!
@IBOutlet weak var imageSelected: UIImageView!
var boxView = UIView()
var window = UIWindow()
@IBOutlet var tableVieww: UITableView!
var imagePicker = UIImagePickerController()
var baseImage: UIImage!
static var secilenKonu = Konu()
var locationManager: CLLocationManager = CLLocationManager()
var latestLocation: CLLocation!
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
aciklamattext.delegate = self
aciklamattext.text = "Açıklama giriniz"
aciklamattext.textColor = UIColor.lightGray
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
latestLocation = nil
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "ileri", style: .plain, target: self, action: #selector(ileriTabbed))
if(StaticObject.KonuList.count == 1){
BildirTableViewController.secilenKonu = StaticObject.KonuList[0]
konuSecimi.text = BildirTableViewController.secilenKonu.Adi
}
NotificationCenter.default.addObserver(self, selector: #selector(BildirTableViewController.konuSecildi), name: NSNotification.Name(rawValue: "konuSecildi"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(BildirTableViewController.resimGoster), name: NSNotification.Name(rawValue: "resimGoster"), object: nil)
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
func textViewDidBeginEditing(_ textView: UITextView) {
if aciklamattext.textColor == UIColor.lightGray {
aciklamattext.text = nil
aciklamattext.textColor = UIColor.black
}
}
func textViewDidEndEditing(_ textView: UITextView) {
if aciklamattext.text.isEmpty {
aciklamattext.text = "Açıklama giriniz"
aciklamattext.textColor = UIColor.lightGray
}
}
override func viewWillAppear(_ animated: Bool) {
if #available(iOS 11.0, *) {
self.title = "Bildir"
self.tabBarController?.navigationItem.title = "Bildir"
self.navigationController?.navigationBar.topItem!.title = "Bildirimler"
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.topItem!.largeTitleDisplayMode = .always
self.navigationItem.largeTitleDisplayMode = .always
} else {
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if(indexPath.row == 1 || indexPath.row == 3){
return 180
}else{
return 45
}
}
@objc func konuSecildi() {
do{
konuSecimi.text = BildirTableViewController.secilenKonu.Adi
}catch{}
}
@objc func resimGoster() {
do{
//self.boxView.removeFromSuperview()
self.imageSelected.image = self.baseImage
}catch{}
}
@objc func ileriTabbed() {
if BildirTableViewController.secilenKonu.Adi == "Seçiniz"{
self.mesajGoster("Konu seçiniz")
return
}
if let temp = aciklamattext.text{
if temp == "Açıklama giriniz"{
self.mesajGoster("Açıklama giriniz")
return
}
}
if StaticObject.gonderilcekNotification.Photo == nil{
self.mesajGoster("Resim çekiniz/seçiniz")
return
}
do{
if latestLocation.coordinate.latitude == 0.0{
self.mesajGoster("Konumunuz alınamadı")
return
}
}catch{
}
StaticObject.gonderilcekNotification.Guid = CFUUIDCreateString(nil, CFUUIDCreate(nil)) as String
StaticObject.gonderilcekNotification.SubjectUID = BildirTableViewController.secilenKonu.UID
StaticObject.gonderilcekNotification.Description = aciklamattext.text
StaticObject.gonderilcekNotification.Longtitude = latestLocation.coordinate.longitude
StaticObject.gonderilcekNotification.Latitude = latestLocation.coordinate.latitude
StaticObject.gonderilcekNotification.PhotoGuid = CFUUIDCreateString(nil, CFUUIDCreate(nil)) as String
//StaticObject.gonderilcekNotification.Photo
self.performSegue(withIdentifier: "toBildiren", sender: nil)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(indexPath.row == 0){
self.performSegue(withIdentifier: "toKonuDetayi", sender: nil)
}else if(indexPath.row == 2){
let alert:UIAlertController=UIAlertController(title: "Seçiniz", message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
let cameraAction = UIAlertAction(title: "Kamera", style: UIAlertActionStyle.default)
{
UIAlertAction in
self.openCamera(self.imagePicker)
}
let galeriAction = UIAlertAction(title: "Galeri", style: UIAlertActionStyle.default)
{
UIAlertAction in
self.openGalery(self.imagePicker)
}
let cancelAction = UIAlertAction(title: "İptal", style: UIAlertActionStyle.cancel)
{
UIAlertAction in
}
// Add the actions
alert.addAction(cameraAction)
alert.addAction(galeriAction)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: nil)
}
tableView.deselectRow(at: indexPath, animated: false)
}
func locationManager(_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation]) {
latestLocation = locations[locations.count - 1]
}
/* override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if(indexPath.row<1){
let cell = tableView.dequeueReusableCell(withIdentifier: "CellId") ?? UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "CellId")
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
cell.textLabel?.text = landmarkNames[indexPath.row]
cell.detailTextLabel?.text = landmarkNames_value[indexPath.row]
return cell
}else{
let cell = UITableViewCell()
return cell
}
} */
func openCamera(_ imagePicker: UIImagePickerController)
{
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.camera))
{
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = true
self .present(imagePicker, animated: true, completion: nil)
}
}
func openGalery(_ imagePicker: UIImagePickerController)
{
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary))
{
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.allowsEditing = true
self .present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
//imageView.image = info[UIImagePickerControllerEditedImage] as? UIImage
baseImage = info[UIImagePickerControllerEditedImage] as? UIImage
self.imageSelected.image = baseImage
StaticObject.gonderilcekNotification.PhotoGuid = CFUUIDCreateString(nil, CFUUIDCreate(nil)) as String
// addSavingPhotoView()
var imageData: Data = UIImageJPEGRepresentation(baseImage, 0.1)!
//var dataToService2
StaticObject.gonderilcekNotification.Photo = imageData.base64EncodedString(options: Data.Base64EncodingOptions.lineLength64Characters)
/* self.asyncInitializeUpload(self.baseImage){
(result:String) in
if(result == "success"){
NotificationCenter.default.post(name: NSNotification.Name(rawValue:"resimGoster"), object: nil)
}
}*/
self.dismiss(animated: true, completion: nil)
}
func addSavingPhotoView() {
// You only need to adjust this frame to move it anywhere you want
boxView = UIView(frame: CGRect(x: view.frame.midX - 90, y: view.frame.midY - 95, width: 180, height: 50))
boxView.backgroundColor = UIColor.white
boxView.alpha = 0.8
boxView.layer.cornerRadius = 10
//Here the spinnier is initialized
let activityView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
activityView.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
activityView.startAnimating()
let textLabel = UILabel(frame: CGRect(x: 45, y: 0, width: 200, height: 50))
textLabel.textColor = UIColor.gray
textLabel.text = "Lütfen Bekleyin"
boxView.addSubview(activityView)
boxView.addSubview(textLabel)
view.addSubview(boxView)
}
func asyncInitializeUpload(_ baseImage: UIImage, completion: @escaping (_ : String) -> Void) {
DispatchQueue.global(qos: .background).async {
//self.baseImage = baseImage
var imageData: Data = UIImageJPEGRepresentation(baseImage, 0.1)!
//var dataToService2
StaticObject.gonderilcekNotification.Photo = imageData.base64EncodedString(options: Data.Base64EncodingOptions.lineLength64Characters)
completion("success")
/* self.uploadPhoto(dataToService2, fotografliBilgiUID: self.fotografliBilgiUID, isFinal: true){
(result:String) in
if(result == "success"){
// completion("success")
}else{
self.boxView.removeFromSuperview()
self.mesajGoster(result)
// completion("fail")
}
}*/
}
}
// MARK: - Table view data source
/*
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)
// Configure the cell...
return cell
}
*/
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment