I am new programming for iOS so I do not know how to solve this problem, I have a view where I have 2 tableview one where you select which chat you want to open and the other table is where the messages are displayed. Now I have 3 problems
At the time of selecting the chat my messages are not automatically shown (Refresh) if not until selecting the tableview chat
When sending a message does not show the gray balloon and the same try to refresh it and even then it only deletes me the messages
That every time a message is sent or shows you the chat the last message is displayed
This is my Table View code
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell:UITableViewCell?
if tableView == self.tableView2 {
let tu = ((identificador[indexPath.row])as NSString).integerValue
if tu == 2{
let cell = tableView.dequeueReusableCell(withIdentifier: "Messages", for: indexPath) as! ChatTableViewCell
cell.emisor.isHidden = true
cell.receptortxt.text = self.chats[indexPath.row]
return cell
}
else if tu == 1{
let cell = tableView.dequeueReusableCell(withIdentifier: "Messages", for: indexPath) as! ChatTableViewCell
cell.receptor.isHidden = true
cell.emisortxt.text = self.chats[indexPath.row]
return cell
}
}
if tableView == self.tableView {
cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell?.textLabel?.text=separated[indexPath.row]
}
return cell!
}
This is the code when you select chat
func peticionhttp()
{
/// Codigo que manda a traer cual chat
self.refresh()
self.boton.setTitle("\(self.separated[0])", for: .normal)
}
}
task.resume()
}
func refresh(){
print("refreshed" , tu2)
self.tableView2.reloadData()
self.tableView2.separatorStyle = .none
}
Code when sending message
@IBAction func onClicEnviar(_ sender: Any) {
// dismissKeyboard()
peticionhttpcuatro()
refresher = UIRefreshControl()
refresher.attributedTitle = NSAttributedString(string: "Pulsa para refrescar")
refresher.addTarget(self, action: #selector(ChatIndividual.refrescar), for: UIControlEvents.valueChanged)
tableView2.addSubview(refresher)
}
@objc func refrescar () {
chats.append(textfield.text!)
identificador += ["1"]
tableView2.reloadData()
refresher.endRefreshing()
print(chats,identificador,"Heeeeeeeeeeeeeeeeeeey ")
}
P.d: I'm not using Firebase