In swift project, I am trying to segue from a one table view controller to another, but after the viewDidLoad
, I get a SIGBRT error. The table view controller that is used to populate the view being segued to inherits many of its properties from another class. Below is the child class.
public class PlacePhotoTVC : PhotoFetcherTVC {
var placeID : String? = nil
public override func viewDidLoad() {
super.viewDidLoad()
if placeID != nil {
self.photos = FlickrFetcher.PhotosInPlace(flickrPlaceId: placeID!, maxResults: 50)
self.places = FlickrPlaces()
self.places.add(place: FlickrFetcher.GetPlace(placeID!)!)
}
}
}
This is the parent class.
public class PhotoFetcherTVC : UITableViewController {
// public API
public var photos : [FlickrPhoto]! = nil {
didSet {
tableView.reloadData()
}
}
public var recentlyViewedPhotos = [FlickrPhoto]()
public var places : FlickrPlaces! = nil
public override func viewDidLoad() {
super.viewDidLoad()
}
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (places.placesSorted(in: (places.countriesSorted()?[section])!)?.count)!
}
public override func numberOfSections(in tableView: UITableView) -> Int {
var numberOfSections = 0
if places != nil {
numberOfSections = (places.countriesSorted()?.count)!
}
return numberOfSections
}
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Photo Cell", for: indexPath)
var title = photos[indexPath.row].title
var description = photos[indexPath.row].description
if title == nil || title!.isEmpty {
title = "Unknown"
}
if description == nil || description!.isEmpty {
description = "Unknown"
}
if title == "Unkown" {
}
cell.textLabel?.text = title
if let locationID = photos[indexPath.row].photoInformation["place_id"] as? String {
let subtitle = FlickrFetcher.GetPlace(locationID)?.region
cell.detailTextLabel?.text = subtitle
}
//tableView.tableHeaderView.
return cell
}
public override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
var sectionHeader : String
if places.countriesSorted()?.count == 0 {
sectionHeader = ""
} else {
sectionHeader = (places.countriesSorted()?[section])!
}
return sectionHeader
}
public override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ViewFlickrPhoto" {
if let cell = sender as? UITableViewCell {
let path = tableView.indexPath(for: cell)
if let destVC = segue.destination as? ImageViewController {
destVC.imageUrl = photos[path!.row].URLforPhoto(format: .flickrPhotoFormatOriginal)
// add the photo the recently viewed photos
var index = 0
for photo in recentlyViewedPhotos {
if photo.id == photos[path!.row].id {
recentlyViewedPhotos.remove(at: index)
break
}
index += 1
}
recentlyViewedPhotos.insert(photos[path!.row], at: 0)
}
}
} //else if segue.i
}
}
I used break points to look at the code and see where the error would throw, and it would throw after going through the viewDidLoad
function from PlacePhotoTVC
and reaching the last bracket of PlacePhototTVC
.