This article was referenced to solve this problem. But I have successfully connected through segue but failed to get data.
link >> Cannot assign value of type String to type UILabel
I am working by embeding TableViewController
after putting ContainerView
in ViewController
.
As I mentioned in the first problem, the connection is successful through segue, but the value is not passed. Which is the problem?
Last time I solved another type of problem, I succeeded, but this time it fails for some reason. I don't know. Any help would be appreciated.
ViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "FreeSegue" {
let filteredBoard = BoardValue?.filter{$0.b_type == "1"}
let mainPageTableVC = segue.destination as? MainPageTableVC
mainPageTableVC?.boards = filteredBoard
}
else if segue.identifier == "GameSegue" {
let filteredBoard = BoardValue?.filter{$0.b_type == "2"}
let mainPageTableVC = segue.destination as? MainPageTableVC
mainPageTableVC?.boards = filteredBoard
}
else if segue.identifier == "FoodSegue" {
let filteredBoard = BoardValue?.filter{$0.b_type == "3"}
let mainPageTableVC = segue.destination as? MainPageTableVC
mainPageTableVC?.boards = filteredBoard
}
else if segue.identifier == "CodingSegue" {
let filteredBoard = BoardValue?.filter{$0.b_type == "4"}
let mainPageTableVC = segue.destination as? MainPageTableVC
mainPageTableVC?.boards = filteredBoard
}
}
MainPageTableVC
import UIKit
class MainPageTableVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
var boards: [BoardList]?
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MainPageViewCell", for: indexPath) as! MainPageTableViewCell
if let boards = self.boards {
let model = boards[indexPath.row]
cell.txtTitle = model.b_title // ERROR [Cannot assign value of type 'String?' to type 'UILabel?']
cell.txtUserId = model.userId // ERROR [Cannot assign value of type 'String?' to type 'UILabel?']
cell.txtConut = model.b_count // ERROR [Cannot assign value of type 'Int?' to type 'UILabel?'
cell.txtSaveTime = model.b_date // ERROR [Cannot assign value of type 'Int?' to type 'UILabel?']
cell.txtComment = model.commentCount // ERROR [Cannot assign value of type 'Int?' to type 'UILabel?']
}
return cell
}
jsonData
struct BoardList: Codable {
var b_id: Int? // no used
var b_recomment_id: Int? // no used
var b_type: String?
var b_title: String?
var b_date: Int?
var b_count: Int?
var userId: String?
var updateCheck: Int? // no used
var commentCount: Int?
}
Simulator Executed Photographs (I drew a line because I thought it might be confusing.)