When adding a text using UITextField from another controller it doesn't show up in the UITableView - ios

I have to create a Web app. I use Split View. In my main view I have and Add button, where I enter the name of the page and its URL, after I press save and it should show up in the UITableView as a new row. All the buttons work, but new row doesn't appear. I'm not sure why.
Here is my main UITableView
import UIKit
import WebKit class WebBrowsers: UITableViewController, NewDelegate {
private var list:[List] = [
List(name: "google", url: URL(string: "https://google.com")),
List(name: "facebook", url: URL(string: "https://www.facebook.com"))
]
#IBOutlet weak var myTableView: UITableView!
#IBAction func addButtonPressed(_ sender: UIBarButtonItem) {
let addContactVC = storyboard?.instantiateViewController(identifier: "AddBrowser") as! AddBrowser
addContactVC.delegate = self
navigationController?.pushViewController(addContactVC, animated: true)
addContactVC.modalPresentationStyle = .fullScreen
}
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Browsers"
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return list.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
cell.textLabel?.text = list[indexPath.row].name
// Configure the cell...
return cell
}
func addSomeCell(name: String?, url:URL!){
let listNew = List.init(name: name,url: url)
self.list.append(listNew)
myTableView.reloadData()
}
/*
// 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: UITableViewCell.EditingStyle, 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 func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
if segue.identifier == "showDetail"{
if let navcon = segue.destination as? UINavigationController{
if let destination = navcon.visibleViewController as? infoBrowser{
if let row = tableView.indexPathForSelectedRow?.row{
destination.detailUrl = list[row].url
destination.navigationItem.title = list[row].name
}
}
}
}
}
}
public protocol NewDelegate: class{
func addSomeCell(name: String?, url:URL!)}
here is my AddButton ViewController
import UIKit
class AddBrowser: UIViewController {
var delegate: NewDelegate?
#IBOutlet weak var nameTextField: UITextField!
#IBOutlet weak var urlTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func saveButtonPressed(_ sender: UIButton) {
self.delegate?.addSomeCell(name: nameTextField.text!, url: URL(string: urlTextField.text!))
navigationController?.popViewController(animated: 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.destination.
// Pass the selected object to the new view controller.
} }

Related

Send data from detail view controller to table view controller

I create an app which uses https://newsapi.org/.
There is a table view that contains news and they have their detail page (Detail View Controller).
Detail view controller has a tab bar button item which is favorites button(<3).
This button send data to favorites table view. But can't send data. Also, in favorites table view you can click the cell and go detail view controller again. So there is two way. And i want to go BACK segue.
main.storyboard:
this is NewsTableViewController:
import UIKit
import Alamofire
class NewsTableViewController: UITableViewController , UISearchBarDelegate {
#IBOutlet weak var searchBar: UISearchBar!
var arr : [Article]? = []
var filteredData: [Article] = []
override func viewDidLoad() {
super.viewDidLoad()
searchBar.delegate = self
//
// let parameters = ["q":"%20", "page": "1", "apiKey":"06c2318ea4c64504b48b3d126168203c"]
let parameters = ["q":"saliha", "page": "1", "apiKey":"06c2318ea4c64504b48b3d126168203c"]
let url = "https://newsapi.org/v2/everything"
AF.request(url, method: .get, parameters: parameters) .responseJSON { (res) in
if(res.response?.statusCode == 200) {
print("res data: ",res.data as Any)
let news = try? JSONDecoder().decode(News.self, from: res.data!)
self.arr = news?.articles
self.tableView.reloadData()
print("kaç sonuç var?",news?.totalResults as Any)
}
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(filteredData.count > 0) {
return filteredData.count
} else {
return arr!.count
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! NewsTableViewCell
let item: Article
if filteredData.count > 0 {
item = filteredData[indexPath.row]
} else {
item = arr![indexPath.row]
}
DispatchQueue.main.async {
let url = URL(string: item.urlToImage!)
let data = try! Data(contentsOf: url!)
cell.newsImage.image = UIImage(data: data)
}
cell.newsTitle.text = item.title
cell.newsAbout.text = item.description
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let sender: Article
if filteredData.count > 0 {
sender = filteredData[indexPath.row]
}
else {
sender = arr![indexPath.row]
}
performSegue(withIdentifier: "detail", sender: sender)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if ( segue.identifier == "detail" ) {
let vc = segue.destination as! DetailViewController
vc.item = (sender as! Article)
}
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
filteredData = []
if searchText == ""{
filteredData = arr!
}
else{
for item in arr!{
if item.title!.lowercased().contains(searchText.lowercased()){
filteredData.append(item)
}
}
}
self.tableView.reloadData()
}
}
this is DetailViewController:
import UIKit
import Alamofire
class DetailViewController: UIViewController {
var item: Article!
var arr: [Article] = []
var favArr: [Article] = []
#IBOutlet weak var dTitle: UILabel!
#IBOutlet weak var dImage: UIImageView!
#IBOutlet weak var dDate: UILabel!
#IBOutlet weak var dAbout: UITextView!
#IBAction func btnWebview(_ sender: Any) {
performSegue(withIdentifier: "goWeb", sender: item)
}
#IBAction func btnFav(_ sender: UIBarButtonItem) {
print("favoriler ekleme butonuna basıldı")
}
#IBAction func btnShare(_ sender: UIBarButtonItem) {
let items = [URL(string: item.url!)]
let ac = UIActivityViewController(activityItems: items as [Any], applicationActivities: nil)
present(ac, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: item.urlToImage!)
let data = try! Data(contentsOf: url!)
dImage.image = UIImage(data: data)
dTitle.text = item.title
dAbout.text = item.description
dDate.text = item.publishedAt
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if ( segue.identifier == "goWeb" ) {
let vc = segue.destination as! WebViewViewController
vc.item = (sender as! Article)
}
}
}
this is FavoriteTableViewController:
import UIKit
import Alamofire
class FavoriteTableViewController: UITableViewController {
var item: Article!
var arr : [Article]? = []
var favArr: [Article] = []
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.reloadData()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return favArr.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "favcell", for: indexPath) as! FavoriteTableViewCell
let url = URL(string: item.urlToImage!)
let data = try! Data(contentsOf: url!)
cell.fImage.image = UIImage(data: data)
cell.fTitle.text = item.title
cell.fDetail.text = item.description
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "detail", sender: item)
}
/*
// 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: UITableViewCell.EditingStyle, 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.destination.
// Pass the selected object to the new view controller.
}
*/
}

Problem tu update tableview, Delegate Hell

first of all I'am renewing my votes with mobile dev almost 4 yeas without any code, a decided to start over new... so is like I'm a newvbie right now!!!
I'm creating a sort of restaurant app, where you can choose pizza, dinks and some other staff that i haven't decided yet.
My problems is..my main view controller I have a UIView and inside it a table view...
I've put a button (the pizza button) that has a segue to another view with a table view controller and data is plenty of pizza info. You have to choose a pizza and then DONE button witch sends data back to my main view controller and this view controller should populate the table view from the choice I've made in the view before.
This is my storyboard
My OrderTableViewController do this:
class OrderTableViewController: UITableViewController {
var orderedItems = OrderList();
override func viewDidLoad() {
super.viewDidLoad()
let noOrder = OrderItem()
noOrder.itemName = "No item Yet"
orderedItems.add(orderItem: noOrder)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true);
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return orderedItems.list.count;
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
// Configure the cell...
let row = indexPath.row
cell.textLabel?.text = orderedItems.list[row].itemName
cell.detailTextLabel?.text = orderedItems.list[row].itemSize
return cell
}
// MARK - Dev methods
func updateTable(orderList:OrderList){
// Here in this line I get que item from my other tableview
print("\(orderedItems.lastSelection) inside OrderTableView");
orderedItems = orderList;
tableView.reloadData();
}
Before call reloadData() I can see that that the result is correctly put on the orderedItem I can even print it
But the method reloadData does nothing.. the view keep showing "no items".
Maybe I misunderstood the whole protocol delegate pattern.
Can you see where is it wrong?
My MainController;
class MainController: UIViewController, PizzaViewControllerDelegate {
var orderedItems = OrderList();
var orderTableVC = OrderTableViewController()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
orderTableVC.updateTable(orderList: orderedItems);
}
func didSelectPizza(pizza: OrderItem) {
orderedItems.add(orderItem: pizza);
orderTableVC.updateTable(orderList: orderedItems);
}
// 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.destination.
// Pass the selected object to the new view controller.
if segue.identifier == "orderSegue" { //embedded view -- keep controller around
orderTableVC = segue.destination as! OrderTableViewController
}
if segue.identifier == "pizzaSegue"{
let pizzaViewController = segue.destination as! PizzaViewController
pizzaViewController.delegate = self
}
}
}
My protocol for pizza:
protocol PizzaViewControllerDelegate {
func didSelectPizza(pizza:OrderItem);
}
protocol PizzaTableViewControllerDelegate {
func didSelectPizzaCell(pizza:String)
}
My PizzaViewController
class PizzaViewController: UIViewController, PizzaTableViewControllerDelegate {
var pizza = OrderItem();
var delegate: PizzaViewControllerDelegate!;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
// 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.destination.
// Pass the selected object to the new view controller.
if segue.identifier == "pizzaTableSegue" {
let vc = segue.destination as! PizzaTableViewController;
vc.delegate = self;
}
}
//IBActions
#IBAction func didCancel(_ sender: Any) {
_ = navigationController?.popViewController(animated: true);
}
#IBAction func didDone(_ sender: UIButton) {
delegate.didSelectPizza(pizza: pizza);
_ = navigationController?.popViewController(animated: true);
}
// MARK -
func didSelectPizzaCell(pizza: String) {
self.pizza.itemName = pizza;
}
}
My PizzaTableViewControlle
class PizzaTableViewController: UITableViewController {
var delegate:PizzaTableViewControllerDelegate! = nil
var pizzaMenu = PizzaMenu();
var pizza = String();
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1;
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return pizzaMenu.menu.count;
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath);
let row = indexPath.row;
cell.textLabel?.text = pizzaMenu.menu[row].pizzaName;
cell.detailTextLabel?.text = pizzaMenu.menu[row].pizzaDescription;
// Configure the cell...
//Making the cell fancy
//font changes
cell.textLabel?.font = UIFont.preferredFont(forTextStyle: .headline)
cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .caption1)
cell.textLabel?.backgroundColor = UIColor.clear
cell.detailTextLabel?.backgroundColor = UIColor.clear
if row % 2 == 0 {
cell.backgroundColor = UIColor(white: 1.0, alpha: 0.7)
} else {
cell.backgroundColor = UIColor(white: 1.0, alpha: 0.5)
}
return cell;
}
// MARK: - TableView Delegate Methods
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
pizza = pizzaMenu.menu[indexPath.row].pizzaName;
delegate.didSelectPizzaCell(pizza: pizza);
}
///This changes cell format on the fly
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return view.frame.size.height/5.0;
}
}
I'm sure that is something I haven't understood yet.. :)
Thanks!!!

TableView is not appending new data

I am trying to create a simple app which lets appending data into an array in first ViewController and then send it to the SecondViewController through the segue. However instead of appending new data it is updating first index of an array.
import UIKit
class ViewController: UIViewController {
var data = [String]()
#IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
#IBAction func sendButton(_ sender: Any) {
if textField.text != nil {
let activity = textField.text
data.append(activity!) //Data should be appended here.
performSegue(withIdentifier: "sendSegue", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "sendSegue" {
let destVC: AppTableViewController = segue.destination as! AppTableViewController
destVC.newData = data
}
}
}
Here is my SecondTableViewController and it just update first index so I am just keep changing my first index instead of adding new values into it.
import UIKit
class AppTableViewController: UITableViewController {
var newData = [String]()
#IBOutlet var myTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return newData.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = newData[indexPath.row]
return cell
}
}
Based on this link,
Please change the function name sendButton to btnSendButton.
So that it will run before prepare.
As of now sendButton is running after prepare. So the data is not appending.

How to go to other view Controller using Navigation Bar Item?

This is my TableViewController: Cells will segue to First controller
import UIKit
class SubjectsTableViewCell: UITableViewCell {
#IBOutlet weak var subjectImage: UIImageView!
#IBOutlet weak var subjectName: UILabel!
}
class AddQuestionTableViewController: UITableViewController {
var Subjects = ["Geology", "Mathematics", "Computer", "English", "History", "Science"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (Subjects.count)
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "pickedSubjectSegue", sender: Subjects[indexPath.row])
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let next = segue.destination as! SubViewController
next.myLabel = sender as! String
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! SubjectsTableViewCell
cell.subjectName?.text = Subjects[indexPath.row]
cell.subjectImage?.image = UIImage(named: (Subjects[indexPath.row] + ".jpeg"))
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
How can I move to second view controller using the Add navigation bar item?
What I tried: ctrl + dragging then modal - failed.
Should I use action or segue? But i already use segue in the table cells.
Any help is greatly appreciated. Thanks
Connect seque to second view controller and give it a name other than the segue that is connected to first view controller i.e. pickedSubjectSegue
Example: "secondSegue"
Then in prepareSegue method check the identifiers of both segues before performing any operation:
Code:
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
if segue.identifier = "pickedSubjectSegue"
{
let next = segue.destination as! SubViewController
next.myLabel = sender as! String
}
else
{
//Write your code here
}
}

View doesn't get updated until the second time loaded

I have a main view which is a table view with a list of countries. When clicking on any country name (cell), another view is loaded via segue which is passing the name of the country to the next view controller's navigation bar title.
The problem is on the first click the title isn't updated, but when I click back button (dismissing the current view) and click on another country name, the second view loads again and shows the previous title that was suppose to be shown on the first attempt.
The code for the first main view controller:
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var sectionsArray = [String]()
var sectionsCountries = [Array<AnyObject>]()
#IBOutlet weak var countries: UITableView!
internal func numberOfSections(in tableView: UITableView) -> Int {
// Return the number of sections.
return self.sectionsArray.count
}
internal func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return self.sectionsCountries[section].count
}
internal func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sectionsArray[section]
}
internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CountryCell", for: indexPath)
cell.textLabel?.text = self.sectionsCountries[indexPath.section][indexPath.row] as? String
return cell
}
var valueToPass:String!
internal func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("You selected cell #\(indexPath.row)!")
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow;
let currentCell = tableView.cellForRow(at: indexPath!) as UITableViewCell!;
valueToPass = currentCell?.textLabel?.text
performSegue(withIdentifier: "cellSegue", sender: self)
//print(valueToPass)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "cellSegue" {
let destination = segue.destination as! CountryViewController
destination.passedValue = valueToPass
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let url = URL(string: "http://cyber7.co.il/swift/countries/countries-list.json")!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if error != nil {
print(error)
} else {
if let urlContent = data {
do {
let jsonResult = try JSONSerialization.jsonObject(with: urlContent, options: JSONSerialization.ReadingOptions.mutableContainers)
for result in jsonResult as! [Dictionary<String, AnyObject>]{
self.sectionsArray.append(result["sectionName"] as! String)
self.sectionsCountries.append(result["sectionCountries"] as! Array<String> as [AnyObject])
}
} catch {
print("JSON Processing Failed")
}
DispatchQueue.main.async(execute: { () -> Void in
self.countries.reloadData()
})
}
}
}
task.resume()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
the code for the second view controller:
import UIKit
class CountryViewController: UIViewController {
var passedValue:String!
#IBOutlet weak var navBar: UINavigationBar!
#IBAction func backButton(_ sender: AnyObject) {
self.dismiss(animated: true, completion: nil)
}
override func viewWillAppear(_ animated: Bool) {
self.navBar.topItem?.title = passedValue
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
When you have a segue set up from a table view cell to a view controller in the storyboard then it is performed automatically when a cell is selected. Your call to perform a segue in your cell selection method is performing the segue a second time after the first one has already been performed.
Remove your tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) method and do all the data passing logic in prepareForSegue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "cellSegue" {
let destination = segue.destination as! CountryViewController
let indexPath = countries.indexPathForSelectedRow
let currentCell = countries.cellForRow(at: indexPath!)
destination.passedValue = currentCell?.textLabel?.text
}
}

Resources