I download some info from Firebase and store that info into my custom annotation class. Then I want to transfer that info to variables on the next view controller so that the table view can properly load. instead of crashing because values are returning nil. I am using a callout accessory button to initiate the segue. And I am using the calloutAccessoryControlTapped function. I understand how to pass Data in general from one ViewController to the next, even better so a tableView, this is unique in that I am using MapKit Annotations, which are similar to tableViewCells, but I am not aware of a MapKit equivalent to indexRow.path that tableViews have.
import Foundation
import UIKit
import MapKit
class BookAnnotation: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
var Author:String?
var Genre: String?
var Comment: String?
var User: String?
var bookPhoto: String?
var userID: String?
var userPhoto: String?
var userLocation: String?
var bookRating: String?
var pushingID: String?
var bookLat: Double?
var bookLng: Double?
init(title: String, Author: String, Genre: String, Comment: String, User: String, bookPhoto: String, userID: String, userPhoto: String, userLocation: String, bookRating: String, pushingID: String, coordinate: CLLocationCoordinate2D){
self.title = title
self.Author = Author
self.Genre = Genre
self.Comment = Comment
self.User = User
self.bookPhoto = bookPhoto
self.userID = userID
self.userPhoto = userPhoto
self.userLocation = userLocation
self.bookRating = bookRating
self.pushingID = pushingID
self.coordinate = coordinate
super.init()
}
var subtitle: String? {
return Comment
}
}
Here is the example that was asked for (Some difference of note. The view sending the information is not a tableView it is a MapView which uses an annotation to display some info and a detail button accesory to go to the next view Controller which is a tableView. So in this function here I cannot use indexPath.row and I did not store things in a dictionary this time as this is a sligtly different kind of view. I hope that makes sense):
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if (segue.identifier == "moreInfo") {
//let navVC = segue.destinationViewController as! UINavigationController
let viewController = segue.destination as! MoreInfoViewController
let indexPath : IndexPath = self.tableView.indexPathForSelectedRow!
let moreInfoSnaphot: FIRDataSnapshot! = self.SecondResultArray[indexPath.row]
let moreInfoCells = moreInfoSnaphot.value as! Dictionary<String, String>
let AuthorInfo = moreInfoCells["Author"] as String!
let CommentInfo = moreInfoCells["Comment"] as String!
let GenreInfo = moreInfoCells["Genre"] as String!
let UserInfo = moreInfoCells["User"] as String!
let titleInfo = moreInfoCells["title"] as String!
let bookPhotoInfo = moreInfoCells["bookPhoto"] as String!
let userIDInfo = moreInfoCells["userID"] as String!
let userPIC = moreInfoCells["userPhoto"] as String!
let userLocation = moreInfoCells["userLocation"] as String!
let userToBePushed = moreInfoCells["pushingID"] as String!
print(userToBePushed)
userPictureURL = userPIC
// This posts the comment about the book in the info view
bookInfoSender = CommentInfo
//These two vars are to handel messageing and can be referenced later
userTobeMessaged = UserInfo
userToBeMessagedId = userIDInfo
////////////////////////////////////////
// initialize new view controller and cast it as your view controller
// your new view controller should have property that will store passed value
viewController.bookComment = bookInfoSender
viewController.UserToBeContacted = UserInfo
viewController.UserContactedID = userToBeMessagedId
viewController.userPictureurl = userPictureURL
viewController.userLocate = userLocation
viewController.bookPictureLink = bookPhotoInfo
viewController.genreOfBook = GenreInfo
viewController.titleOfBook = titleInfo
viewController.userBeingPushedMSG = userToBePushed
print("THIS IS THE USER TO BE PUSHED \(userToBePushed)")
}
}